Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize subscriber's next/error/complete algorithm infra, for internally-subscribed Observables #95

Merged
merged 4 commits into from
Jan 4, 2024

Conversation

domfarolino
Copy link
Collaborator

@domfarolino domfarolino commented Jan 4, 2024

This allows for the Promise-returning operators to subscribe to an Observable with an internally spec-defined set of steps for next/error/complete.


Preview | Diff

@domfarolino domfarolino merged commit 6843362 into master Jan 4, 2024
2 checks passed
@domfarolino domfarolino deleted the observable-internal-observer branch January 4, 2024 18:13
github-actions bot added a commit that referenced this pull request Jan 4, 2024
…rnally-subscribed Observables (#95)

SHA: 6843362
Reason: push, by domfarolino

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
aarongable pushed a commit to chromium/chromium that referenced this pull request Jan 12, 2024
In the Observable specification, recently
WICG/observable#95 generalized the collection of
"next", "error", "complete" handlers into an "internal observer" concept
that the `Subscriber` interface is responsible for holding. This was an
abstraction exercise to make it possible to supply arbitrary observer
handlers, instead of just JavaScript callback functions passed into
`Observable::subscribe()`, via the `ObserverUnion`.

This abstraction is crucial for the Observable API, because it is not
only developer JavaScript code that is responsible for subscribing to
observables. Native "internal" code can also subscribe to an existing
Observable, via the Promise-returning operators [1]. These operators
internally subscribe to an Observable and return a Promise that resolves
or rejects according to the operator's semantics. The Promise resolves
or rejects with values accumulated via the "internal" next, error, and
complete handlers.

To achieve this in the implementation, we introduce a
`blink::ObservableInternalObserver` class mirroring the spec's "internal
observer" struct [2]. This is an abstract interface with overridable
`Next`, `Error`, and `Complete` algorithms. `blink::Subscriber` holds
onto this class, and subclasses of this interface provide the concrete
implementations of those algorithms.

Because no Promise-returning operators are implemented yet, the only
consumer/subclass of this abstract interface is the
`ScriptCallbackInternalObserver` that `observable.cc` provides. It is
responsible for implementing the logic that much of `blink::Subscriber`
currently implements (before this CL). This is typically trivial logic
like storing the user-supplied `ObserverUnion` callback functions,
calling them if they are non-null, and reporting exceptions if the
callbacks throw any errors.

With this logic outsourced to the specific
`ScriptCallbackInternalObserver`, and no longer hard-coded inside
`Subscriber`, Subscriber can be more concerned with logic pertaining to
subscription management, and less with Observer-specific logic.
Subsequent CLs will implement specific subclasses of this generic
interface to provide the Promise-returning operator implementations.

[1]: https://wicg.github.io/observable/#promise-returning-operators
[2]: https://wicg.github.io/observable/#internal-observer

[email protected]

Bug: 1485981
Change-Id: I524f0de89dab23a896b1f6f4783c0168b1fa6c0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5178410
Commit-Queue: Dominic Farolino <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1246676}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant