A little Functional
& Reactive
programming library.
Add TanDeferred
in your Podfile
:
use_frameworks!
pod "TanDeferred"
Then run the following command:
$ pod install
- Download the source code.
- Drag folder Deferred/Deferred into your project.
// Create an instance of Deferred
Deferred *deferred = [Deferred deferred];
// Subscribe
[deferred subscribe:^(id _Nullable value) {
NSLog(@"%@", value);
}];
// Just fill it
[deferred fill:@"Hello World"];
Or you can create with an initialized value:
Deferred *deferred = [Deferred just:@"Hello World"];
[[[deferred map:^id _Nullable(id _Nullable value) {
return [value stringByAppendingString:@"Good morning"];
}] flatMap:^Deferred * _Nonnull(id _Nullable value) {
return [Deferred just:[value stringByAppendingString:@"Good night"]];
}] subscribe:^(id _Nullable value) {
NSLog(@"%@", value);
}];
There are four
queues to control Deferred
to execute missions with multi-thread
:
- MainQueue
- SyncQueue (Default)
- AsyncQueue
- CustomQueue
[[deferred mapOn:[AsyncQueue shared] with:^id _Nullable(id _Nullable value) {
return [value stringByAppendingString:@"Baby"];
}] subscribeOn:[MainQueue shared] with:^(id _Nullable value) {
NSLog(@"%@", value);
}];
The MIT License (MIT)