retry an take added

This commit is contained in:
Carlos García 2015-06-21 10:57:41 +02:00
parent c85e028e6a
commit 95ba612334
7 changed files with 68 additions and 25 deletions

View File

@ -51,3 +51,48 @@ example("catch") {
}
/*:
## `retry`
If a source Observable emits an error, resubscribe to it in the hopes that it will complete without error
[More info in reactive.io website]( http://reactivex.io/documentation/operators/retry.html )
*/
example("retry") {
var count = 1 // bad practice, only for example purposes
let observable: Observable<Int> = create { observer in
let error = NSError(domain: "Test", code: 0, userInfo: nil)
sendNext(observer, 0)
sendNext(observer, 1)
sendNext(observer, 2)
if count < 2 {
sendError(observer, error)
count++
}
sendNext(observer, 3)
sendNext(observer, 4)
sendNext(observer, 5)
sendCompleted(observer)
return AnonymousDisposable {}
}
observable
>- retry
>- subscribe { event in
switch event {
case .Next(let box):
println("\(box.value)")
case .Completed:
println("completed")
case .Error(let error):
println("\(error)")
}
}
}

View File

@ -37,4 +37,19 @@ example("distinctUntilChanged") {
>- subscribeNext { value in
println("\(value)")
}
}
}
/*:
### `take`
Emit only the first n items emitted by an Observable
[More info in reactive.io website]( http://reactivex.io/documentation/operators/take.html )
*/
example("take") {
let distinctUntilChangedSubscriber = returnElements(1, 2, 3, 4, 5, 6)
>- take(3)
>- subscribeNext { value in
println("\(value)")
}
}

View File

@ -99,4 +99,4 @@ example("scan") {
>- subscribeNext {
println($0)
}
}
}

View File

@ -85,7 +85,7 @@ example("subscribeError") {
### `do`
Returns the same source Observable but the given closure responsible for the actions to perform when the even is produced. The gived closure obtain the event produced by the source observable
[More info in reactive.io website](http://reactivex.io/documentation/operators/do.html)
[More info in reactive.io website]( http://reactivex.io/documentation/operators/do.html )
*/
example("do") {
@ -108,7 +108,7 @@ example("do") {
/*:
### `doOnNext`
It is a variant of the `do` operator. Returns the same source Observable but the given closure responsible for the actions to perform when the Next even is produced. The gived closure obtain the value of the Next event produced by the source observable.
[More info in reactive.io website](http://reactivex.io/documentation/operators/do.html)
[More info in reactive.io website]( http://reactivex.io/documentation/operators/do.html )
*/
example("doOnNext") {
@ -127,24 +127,3 @@ example("doOnNext") {
sendNext(intOb1, 1)
}
/*:
### `observeSingleOn`
Specify the Scheduler on which an observer will observe this Observable
[More info in reactive.io website](http://reactivex.io/documentation/operators/observeon.html)
*/
//TODO: Do not work in playgrounds
example("observeSingleOn") {
let intOb1 = Subject<Int>()
intOb1
>- observeSingleOn(MainScheduler.sharedInstance)
>- subscribeNext { int in
println(int)
}
sendNext(intOb1, 1)
}

View File

@ -88,6 +88,7 @@
C811086F1AF5114D001C13E4 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0630;
ORGANIZATIONNAME = "Krunoslav Zaher";
TargetAttributes = {
@ -236,6 +237,7 @@
C81108801AF5114D001C13E4 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};

View File

@ -253,6 +253,7 @@
C81553D51A98AB4A00C63152 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Krunoslav Zaher";
TargetAttributes = {

View File

@ -323,6 +323,7 @@
C81108161AF50DDA001C13E4 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0630;
TargetAttributes = {
C811081F1AF50E11001C13E4 = {