Skip to content

Defer factory should return ObservableInput, not just Subscribable | PromiseLike #2586

@felixfbecker

Description

@felixfbecker

Observable.defer() takes a factory that takes Subscribable | PromiseLike. That is very annoying when the value is available synchronously and often results in a lot of boiler plate when usingconcat(). Simplified example:

const contents = new Map<string, string>();

getFilesInWorkspace()
  .mergeMap(uri =>
    // ensureContent emits no items, just completes once content is ensured
    ensureContent(uri)
      // After that, we can get the content synchronously
      // Need Observable.of() here because just returning an array is not allowed
      .concat(Observable.defer(() => Observable.of(contents.get(uri))))
  )
  .mergeMap(content => ...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions