Swift nio Thread safe

    func queueDemo(req: Request) -> EventLoopFuture<String> {
        // search,
        let users = InsUserInfo.query(on: req.db).range(0..<20).all()
        // update
        return users.flatMapEach(on: req.eventLoop) { info -> EventLoopFuture<[String]> in
            let json = ClientJsonModel.init(id: info.userId)
            let userId = json.id
            let edges = json.edges
            
            // Info
            return InsUserInfo.query(on: req.db)
            .filter(\.$userId == userId)
            .first()
            .flatMap { userInfo -> EventLoopFuture<[String]> in
                //  download
                let codes = edges.map { edge -> EventLoopFuture<String> in
                    // why error
                    assert(userId != edge.id, "userId != edge.id")
                    return req.eventLoop.makeSucceededFuture("")
                }
                return codes.flatten(on: req.eventLoop)
                    .flatMap { firstItem in
                        // todo
                        return req.eventLoop.makeSucceededFuture(firstItem)
                    }
            }
        }.map { _ in "ok"}
    }
    
    struct ClientJsonModel: Codable {
        let id: String
        let edges: [ClientJsonEdgesModel]
        
        struct ClientJsonEdgesModel: Codable {
            let id: String
            let shortcode: String
        }
        
        init(id: String) {
            self.id = id
            var tempEdges = [ClientJsonEdgesModel]()
            for index in 0..<50 {
                let edge = ClientJsonEdgesModel.init(id: id, shortcode: "\(id)_\(index)")
                tempEdges.append(edge)
            }
            self.edges = tempEdges
        }
    }

why userId != edge.id

Hello @0xTim, can you help me solve it?
I don't know what is the logic problem with this code.
Thank you so much。

It's very hard to say without context. My suggestion would be to step through with a debugger when you create the edges and see what's happening

Terms of Service

Privacy Policy

Cookie Policy