Async library inspired by CommonJS Promises/A spec
http://wiki.commonjs.org/wiki/Promises/A
Via Cocoapods:
pod 'KSDeferred'
KSDeferred *deferred = [KSDeferred defer];
return deferred.promise;
[promise then:^id(id value) {
.. do something ..
return value;
} error:^id(NSError *e) {
.. handle error ..
return e;
}];
KSPromise *chained = [promise then:^id(id value) {
return value;
} error:^id(NSError *e) {
return e;
}];
[chained then:^id(id value) {
# value is value returned from first promise
} error:^id(NSError *e) {
# error is error returned from first promise
}];
KSPromise *chained = [promise then:^id(id value) {
KSDeferred *nextDeferred = [KSDeferred defer];
return nextDeferred.promise;
} error:^id(NSError *e) {
return e;
}];
[chained then:^id(id value) {
# value is value the returned promise resolves with
} error:^id(NSError *e) {
# error is error the returned promise rejects with
}];
[deferred resolveWithValue:@"VALUE"];
NSError *someError;
[deferred rejectWithError:someError];
- Kurtis Seebaldt, Pivotal Labs
Copyright (c) 2013 Kurtis Seebaldt. This software is licensed under the MIT License.