TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Feb 2015 |
SPMSupports SPM | ✗ |
Maintained by Cameron Pulsford.
Swift framework for Promises and Futures focusing on a small and simple API.
First, drop the following line in your Podfile
pod 'Futures', '~> 2.0'
Then, just import Futures
and go!
let f = Future<Int>() { _ in
.Success(Box(fibonacci(16)))
}
f.onSuccess() {
println($0) // 987
}
Note: The use of the Box class to return successful results is due to a (seemingly temporary) shortcoming in Swift right now where all of an enum’s associated values must be of a known size at compile time.
future(fibonacci(16)).onSuccess() {
println($0) // 987
}
Future<Int>() { _ in
.Error(NSError())
}.onSuccess() { value in
// handle value
}.onError() { error in
// handle error
}
if let fib16 = future(fibonacci(16)).successValue {
println(fib16) // 987
}
if let fib16 = future(fibonacci(16)).valueWithTimeout(10)?.successValue {
println(fib16) // 987
}
let queue = dispatch_queue_create("Test", DISPATCH_QUEUE_SERIAL)
// somewhere else
let f = queue.createFuture(fibonacci(16))
FutureCache is a simple and useful way to initialize and cache expensive values.
let futureCache = FutureCache<Int>()
futureCache.add("fib16", future: future(fibonacci(16)))
// later...
let expensiveResult = futureCache.valueForKey("fib16")!
Initial release.
Adds some missing documentation.
Adds FutureCache.
Adds missing doc strings for onSuccess and onError methods.
Updates to Swift 1.2. This kills the @autoclosure. :-(
Fixes a possible dead lock if you used the .state property in a work/onSuccess/onError closure of a Promise or Deref.
Adds extensions to dispatch_queue_t for creating associated futures.
FutureResult
into a DerefResult
. .value
now returns a DerefValue<T>
. .successValue
has been added as a convenience to get the old behavior of .value
.isCanceled
block which the workBlock may check periodically to stop expensive work early. This works much like a custom NSOperation subclass might. Simple shorthand still exists for Futures that are known to only succeed and which do not care about cancellation.@autoclosure(escaping)
shorthand for futures. Hooray! Requires Xcode 6.3 beta 2.@autoclosure(escaping)
.