LoginSignup
0
0

More than 5 years have passed since last update.

Observableを順番に処理させるサンプル

Posted at

これで良いかどうかは置いておいて、このサンプルでは5秒毎に「1,2,3」と表示して終わるサンプルです。
あとで、僕が使うメモです。

        let a:Observable<Int> = Observable.create { observable in
            NSOperationQueue().addOperationWithBlock({ () -> Void in
                sleep(5)
                observable.onNext(1)
                observable.onCompleted()
            })
            return NopDisposable.instance
        }

        let b:Observable<Int> = Observable.create { observable in
            NSOperationQueue().addOperationWithBlock({ () -> Void in
                sleep(5)
                observable.onNext(2)
                observable.onCompleted()
            })
            return NopDisposable.instance
        }

        let c:Observable<Int> = Observable.create { observable in
            NSOperationQueue().addOperationWithBlock({ () -> Void in
                sleep(5)
                observable.onNext(3)
                observable.onCompleted()
            })
            return NopDisposable.instance
        }

        a.concat(b).concat(c).subscribeNext { (value) in
            print(value)
        }
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0