Skip to content

Commit bd84927

Browse files
committed
Editorial changes for Event Streams
This makes a few changes to the Subscriptions section where we're talking about event streams in an attempt to make it more clear about what's going on. - Revised variable names from "fieldStream" to "sourceStream" to make it easier to trace variables through algorithms. - Rewrote the "Event Streams" definition to be more clear about "emit" keyword and have clear paragraphs on completion and cancellation. - Rewrote the `MapSourceToResponseEvent` algorithm to be a correctly formatted algorithm with a return statement at the end. Introduced a new "When" keyword to describe event subscriptions. Added explicit sections on passing back cancellation (discussed in WG) as well as completion with error (not discussed, but I realized was also left ambiguous)
1 parent 497e333 commit bd84927

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

spec/Section 6 -- Execution.md

+25-16
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,17 @@ chat room ID is the "topic" and each "publish" contains the sender and text.
217217

218218
**Event Streams**
219219

220-
An event stream represents a sequence of discrete events over time which can be
221-
observed. As an example, a "Pub-Sub" system may produce an event stream when
222-
"subscribing to a topic", with an event occurring on that event stream for each
223-
"publish" to that topic. Event streams may produce an infinite sequence of
224-
events or may complete at any point. Event streams may complete in response to
225-
an error or simply because no more events will occur. An observer may at any
226-
point decide to stop observing an event stream by cancelling it, after which it
227-
must receive no more events from that event stream.
220+
An event stream represents a sequence of discrete emitted events over time
221+
which can be observed. As an example, a "Pub-Sub" system may produce an event
222+
stream when "subscribing to a topic", with an event emitted for each "publish"
223+
to that topic.
224+
225+
Event streams may complete at any point, often because no further events will
226+
occur. Event streams may emit an infinite sequence of events, in which they
227+
may never complete. If an event stream encounters an error, it must complete
228+
with that error.
229+
230+
An observer may at any point decide to stop observing an event stream by cancelling it. When an event stream is cancelled, it must complete.
228231

229232
**Supporting Subscriptions at Scale**
230233

@@ -268,10 +271,10 @@ CreateSourceEventStream(subscription, schema, variableValues, initialValue):
268271
- Let {field} be the first entry in {fields}.
269272
- Let {argumentValues} be the result of {CoerceArgumentValues(subscriptionType,
270273
field, variableValues)}.
271-
- Let {fieldStream} be the result of running
274+
- Let {sourceStream} be the result of running
272275
{ResolveFieldEventStream(subscriptionType, initialValue, fieldName,
273276
argumentValues)}.
274-
- Return {fieldStream}.
277+
- Return {sourceStream}.
275278

276279
ResolveFieldEventStream(subscriptionType, rootValue, fieldName, argumentValues):
277280

@@ -292,12 +295,18 @@ subscription _selection set_ using that event as a root value.
292295

293296
MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):
294297

295-
- Return a new event stream {responseStream} which yields events as follows:
296-
- For each {event} on {sourceStream}:
298+
- Let {responseStream} be a new event stream.
299+
- When {sourceStream} emits {event}:
297300
- Let {response} be the result of running
298301
{ExecuteSubscriptionEvent(subscription, schema, variableValues, event)}.
299-
- Yield an event containing {response}.
300-
- When {sourceStream} completes: complete {responseStream}.
302+
- Emit {response} on {responseStream}.
303+
- When {sourceStream} completes normally:
304+
- Complete {responseStream} normally.
305+
- When {sourceStream} completes with {error}:
306+
- Complete {responseStream} with {error}.
307+
- When {responseStream} is cancelled:
308+
- Cancel {sourceStream}.
309+
- Return {responseStream}.
301310

302311
ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
303312

@@ -317,8 +326,8 @@ Note: The {ExecuteSubscriptionEvent()} algorithm is intentionally similar to
317326
#### Unsubscribe
318327

319328
Unsubscribe cancels the Response Stream when a client no longer wishes to
320-
receive payloads for a subscription. This may in turn also cancel the Source
321-
Stream. This is also a good opportunity to clean up any other resources used by
329+
receive payloads for a subscription. This in turn also cancels the Source
330+
Stream, which is a good opportunity to clean up any other resources used by
322331
the subscription.
323332

324333
Unsubscribe(responseStream):

0 commit comments

Comments
 (0)