美文网首页
Promise of vapor

Promise of vapor

作者: hhcszgd | 来源:发表于2019-08-03 16:09 被阅读0次

    Promise

    Most of the time, you will be transforming futures returned by calls to Vapor's APIs. However, at some point you may need to create a promise of your own.

    To create a promise, you will need access to an EventLoop. All containers in Vapor have an eventLoop property that you can use. Most commonly, this will be the current Request.

    
    /// Create a new promise for some string
    let promiseString = req.eventLoop.newPromise(String.self)
    print(promiseString) // Promise<String>
    print(promiseString.futureResult) // Future<String>
    
    /// Completes the associated future
    promiseString.succeed(result: "Hello")
    
    /// Fails the associated future
    promiseString.fail(error: ...)
    
    

    相关文章

      网友评论

          本文标题:Promise of vapor

          本文链接:https://www.haomeiwen.com/subject/yuwjdctx.html