Swift NIO EventLoopF​​uture 链未完成

Swift NIO EventLoopFuture chain not completing

我有一个基于 Vapor 应用程序构建的非常简单的服务。该服务使用来自另一系列服务的数据。显然,这正是 map 方法的应用类型。

链中的所有回调都执行,但链中的最后一个 EventLoopFuture 从未完成,导致我的服务无限期挂起。

此代码进行一次异步调用以获取会话 ID,然后使用该数据检查某人是否是特定组的成员。对其他服务的调用 return 合理值 - 目前第二次调用总是 return 错误。

当我调用此方法时,所有回调都按预期执行和运行。

请注意,在此代码片段中,我已“解开”序列的各个阶段,以试图阐明问题出现的位置,但整体行为并未受到影响。

我尝试了链的许多不同排列,在适当的地方使用 flatMapmapflatMapError,而没有改变最终结果。

let authService = remoteApi.authServices();

// EventLoopFuture<String> with sessionId
let sessionIdFuture = authService.getSessionId(username: userName, password: password)

// EventLoopFuture<Bool> with whether the user is in a particular group
let gsFuture = sessionIdFuture.flatMap { sessionId -> EventLoopFuture<Bool> in
    let groupMemberService = remoteApi.groupMemberServices()
    return groupMemberService.personIsInGroup(sessionId: sessionId, groupId: groupId, userId: userId)
}

// EventLoopFuture<Bool> if the above has an error, just return false
let errorFuture = gsFuture.flatMapErrorThrowing { error in
    // This executes successfully!
    return false
}

// EventLoopFuture<String> with the return data 
let returnFuture = errorFuture.flatMapThrowing { isMember -> String in
    // This executes successfully!
    let response = PersonIsMemberResponse(isMember: isMember)
    if let json = self.encodeResponse(response) {
        print(json) // {"isMember": false}
        return json
    } else {
        throw Abort(.internalServerError, reason: "could not encode our own dang data type");
    }
}.always { result in
    // This executes!
    do {
        try remoteApi.shutdown()
    } catch {
        print(error)
    }
}

gsFuture.whenComplete { result in
    // This executes!
    print("gsFuture complete!")
}
errorFuture.whenComplete { result in
     // This executes!
   print("errorFuture complete!")
}
returnFuture.whenComplete { result in
    // This DOES NOT execute!
    print("returnFuture complete!")
}

我看不出最后一个flatMapThrowing和return一个值是怎么执行的,那以后就不完整了。我错过了什么?

正如我们在评论中共同发现的那样,try remoteApi.shutdown() 似乎正在阻止进一步发生任何事情。