Skip to content

Use Promise to Replace Observable Only Emitting Once #233

@seanwu1105

Description

@seanwu1105

Since currently there is no Single class (like rxjava) in rxjs, it could be difficult for developers to figure out if the Observable only emits once. There are several discussion about this problem. E.g. ReactiveX/rxjs#5273.

We should use Promise instead of Observable to clearly indicate the behavior will only return ONE SINGLE value asynchronously. This would help developers to avoid lots of potential bugs when deciding which observable operator to use, such as forkJoin vs zip and toArray vs scan.

As a Promise can be easily transform into an Observable with defer function but it is an anti-pattern to transform an Observable into a Promise via toPromise function, we should:

  • Prefer Promise than Observable for return values.
  • Prefer Observable than Promise for parameters.

Metadata

Metadata

Assignees

Labels

codeImprovements to code quality or project architecture

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions