RxJS sequence equivalent to promise.then()?

前端 未结 8 1390
南旧
南旧 2020-11-28 05:12

I used to develop a lot with promise and now I am moving to RxJS. The doc of RxJS doesn\'t provide a very clear example on how to move from promise chain to observer sequenc

8条回答
  •  迷失自我
    2020-11-28 05:20

    If I understood correctly, you mean consuming the values, in which case you use sbuscribe i.e.

    const arrObservable = from([1,2,3,4,5,6,7,8]);
    arrObservable.subscribe(number => console.log(num) );
    

    Additionally, you can just turn the observable to a promise using toPromise() as shown:

    arrObservable.toPromise().then()
    

提交回复
热议问题