How do you return new Observable(function(observer) { … with RxJS v5?

♀尐吖头ヾ 提交于 2019-12-08 20:43:14

问题


I am trying to replace all the promises that my functions return with Observables. From this post, I learned that I should no longer use "new Observable" Observable.forkJoin and array argument

What is the RxJS v5 syntax to achieve this as such to achieve asynchronous waiting?

thirdFunction() {

    let _self = this;

    return new Observable(function(observer) {

        ...

        observer.next( responseargs );
        observer.complete();
    });
}

Thank you greatly for help you can offer.


回答1:


There are a set of methods to create observables for different use cases:

  • of - create an observable and directly trigger an event with the provided value
  • timeout - create an observable that triggers an event after an amount of time
  • interval - create an observable that triggers repeatly after an amount of time

This link provides a list of them by category:

  • https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/categories.md


来源:https://stackoverflow.com/questions/35800792/how-do-you-return-new-observablefunctionobserver-with-rxjs-v5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!