我正在使用 swift perfect 2.0,我需要在 10 秒后调用一个函数。我可以使用以下代码使其在普通的 iOS 应用程序上运行:
let when = DispatchTime.now() + 10
DispatchQueue.main.asyncAfter(deadline: when){
//call function
}
但是我不能快速完美地做到这一点,而且我不知道如何工作。这是我的请求的结构:
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() 之前,我可能想错了。所以我的问题是,有没有其他方法可以在完美 2.0 中使用 Dispatchqueues?它们似乎不起作用。