Created
March 21, 2018 11:50
-
-
Save olbrichj/c76e2f5933bfaf6c68632925f4f593e6 to your computer and use it in GitHub Desktop.
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 foo() -> (Promise<Void>, cancel: () -> Void) { | |
let task = Task(…) | |
var cancelme = false | |
let promise = Promise<Void> { seal in | |
task.completion = { value in | |
guard !cancelme else { reject(NSError.cancelledError) } | |
seal.fulfill(value) | |
} | |
task.start() | |
} | |
let cancel = { | |
cancelme = true | |
task.cancel() | |
} | |
return (promise, cancel) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment