Skip to main content
Deno 2 is finally here 🎉️
Learn more
Latest
class ResultStreamObserver
import { ResultStreamObserver } from "https://deno.land/x/neo4j_lite_client@4.4.6/bolt-connection/bolt/stream-observers.js";

Handles a RUN/PULL_ALL, or RUN/DISCARD_ALL requests, maps the responses in a way that a user-provided observer can see these as a clean Stream of records. This class will queue up incoming messages until a user-provided observer for the incoming stream is registered. Thus, we keep fields around for tracking head/records/tail. These are only used if there is no observer registered.

Constructors

new
ResultStreamObserver(unnamed 0?)

Methods

_handleRunSuccess(meta, afterSuccess)
_setState(state)
_setupAuoPull(fetchSize)

Cancel pending record stream

Mark this observer as if it has completed with no metadata.

onError(error)

Will be called on errors. If user-provided observer is present, pass the error to it's onError method, otherwise set instance variable _error.

onNext(rawRecord)

Will be called on every record that comes in and transform a raw record to a Object. If user-provided observer is present, pass transformed record to it's onNext method, otherwise, push to record que.

Stream observer defaults to handling responses for two messages: RUN + PULL_ALL or RUN + DISCARD_ALL. Response for RUN initializes query keys. Response for PULL_ALL / DISCARD_ALL exposes the result stream.

However, some operations can be represented as a single message which receives full metadata in a single response. For example, operations to begin, commit and rollback an explicit transaction use two messages in Bolt V1 but a single message in Bolt V3. Messages are RUN "BEGIN" {} + PULL_ALL in Bolt V1 and BEGIN in Bolt V3.

This function prepares the observer to only handle a single response message.

subscribe(observer)

Subscribe to events with provided observer.