Created
January 11, 2019 12:48
-
-
Save gabrielepalma/dd70126165a26c8334335f6621289110 to your computer and use it in GitHub Desktop.
Using wait in future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func deleteStuff(_ request: Request) throws -> Future<SomeKindOfType> | |
{ | |
let promise = request.eventLoop.newPromise(of: SomeKindOfType.self) | |
DispatchQueue.global().async { | |
guard let decodedBody = try? request.content.decode(ExpectedRequestBody.self).wait() else { | |
promise.fail(error: Abort(HTTPResponseStatus.badRequest)) | |
return | |
} | |
try? SomeFluentType.query(on: request).filter(somefilter).delete().wait() | |
promise.succeed(result: SomeKindOfType()) | |
} | |
return promise.futureResult | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment