在 swift 3 perfect 2.0 中使用 Dispatch queue

Using Dispatch queue in swift 3 perfect 2.0

我正在使用 swift perfect 2.0,我需要在 10 秒后调用一个函数。我可以使用以下代码使其在普通 iOS 应用程序上运行:

let when = DispatchTime.now() + 10
DispatchQueue.main.asyncAfter(deadline: when){
    //call function
}

但我无法做到 swift 完美,而且我不知道如何工作。这是我请求的结构:

public func InsertPost(_ request: HTTPRequest, response: HTTPResponse)

    //logic

    response.status = .custom(code: 200, message: "Success!")
    response.completed()

    //here i want to send a notification to some users, but only after 10 seconds. 
    //So i try to call function sendNotifications() like this:

    let when = DispatchTime.now() + 10
    DispatchQueue.main.asyncAfter(deadline: when){
        sendNotifications()
    }
{

它从不调用 sendNotifications(),即使我将它放在 response.completed() 之前,我可能想错了。所以我的问题是,有没有其他方法可以在 perfect 2.0 中使用 Dispatchqueues?它们似乎不起作用。

看起来 perfect 2.0 有自己的线程管理设置。检查这个 link:

http://perfect.org/docs/thread.html

好的,我明白了。我无法在 swift 完美中阻塞主队列。

解决方案:

let backgroundQueue = DispatchQueue(label: "com.app.queue", qos: .background, target: nil)

let when = DispatchTime.now() + 10
backgroundQueue.asyncAfter(deadline: when){
    //call function
}