Search code examples
javascriptrxjsreactivex

Which operators will cause an Observable to evaluate?


I am working with rxjs in particular, but I am asking about ReactiveX in general.

There are many mentions that Oberservable are lazily evaluated, but searching through the docs, I cannot find explicit mention of which operators will cause an Observable to be evaluated. The only operator I know of that will cause evaluation is subscribe. Are there other options?


Solution

  • It is the only operator you need. In order to trigger an Observable, you need to subscribe to it. No need to do anything with the results, you only need to subscribe:

    functionThatReturnsAnObservable().subscribe(function(data){});
    

    Edit
    As cartant said, there are functions that implicitly invoke the subscribe operator, such as the forEach and toPromise functions.