EsStreamPromise
Description
A single-subscription stream where the contents are provided later.
It is generally recommended that you never create an <EsFuture> that completes with an <EsStream> because you can just directly create a stream that doesn't do anything until it's ready to do so. This class can be used to create such a stream.
The stream inst var is a normal stream that you can listen to immediately, but until either #setSourceStream or #setEmpty is called, the stream won't produce any events.
The same effect can be achieved by using a <EsStreamController> and adding the stream using #addStream: when both the controller's stream is listened to and the source stream is ready. This class attempts to shortcut some overhead when possible.
For example, if the stream inst var is only listened to after the source stream has been set, the listen is performed directly on the source stream.
Instance State
Class Methods
<details> fromFuture:
<pre><code> Convert an <EsFuture> (one that completes with an <EsStream>) to an <EsStream>.
This creates a stream using a stream promise,
and sets the source stream to the result of the future when the
future completes.
If the future completes with an error, the returned stream will
instead contain just that error.
Arguments:
streamFuture - <EsFuture> that completes with <EsStream>
Answers:
<EsStream>
</code></pre> </details>
<details> new
<pre><code> Answer a new initialized instance of <EsStreamPromise>
Answers:
<EsStreamPromise>
</code></pre> </details>
Instance Methods
<details> setEmpty
<pre><code> Equivalent to setting an empty stream using #setSourceStream:.
Any one of #setSourceStream:, #setEmpty, and #setError may be called at
most once. Trying to call any of them again will fail.
</code></pre> </details>
<details> setError:
<pre><code> Completes this to a stream that emits @error and then closes.
This is useful when the process of creating the data for the stream fails.
Any one of #setSourceStream:, #setEmpty, and #setError:* may be called at
most once. Trying to call any of them again will fail.
Arguments:
error - <Object>
</code></pre> </details>
<details> setError:stackTrace:
<pre><code> Completes this to a stream that emits @error and then closes.
This is useful when the process of creating the data for the stream fails.
Any one of #setSourceStream:, #setEmpty, and #setError:* may be called at
most once. Trying to call any of them again will fail.
Arguments:
error - <Object>
stackTrace - <EsAsyncStackTrace>
</code></pre> </details>
<details> setSourceStream:
<pre><code> Set a stream as the source of events for the <EsStreamPromise>'s stream
The promise's `stream` will act exactly as @aSourceStream
If the source stream is set before `stream` is listened to,
the listen call on `stream` is forwarded directly to @aSourceStream
If `stream` is listened to before setting the source stream,
an intermediate subscription is created. It looks like a completely
normal subscription, and can be paused or canceled, but it won't
produce any events until a source stream is provided.
If the `stream` subscription is canceled before a source stream is set,
the source stream will be listened to and immediately canceled again.
Otherwise, when the source stream is then set,
it is immediately listened to, and its events are forwarded to the
existing subscription.
Any one of #setSourceStream:, #setEmpty, and #setError may be called at
most once. Trying to call any of them again will fail.
Arguments:
aSourceStream - <EsStream>
</code></pre> </details>
<details> stream
<pre><code> The stream of this promise.
This stream is always a single-subscription stream.
When a source stream is provided, its events will be forwarded to
listeners on this stream.
The stream can be listened either before or after a source stream
is set.
Answers:
<EsStream>
</code></pre> </details>
Last modified date: 04/21/2022