Skip to content

Commit 5bb1e07

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 f8f2fac commit 5bb1e07

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

spec/Section 6 -- Execution.md

+29-19
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,18 @@ 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 which
221+
can be observed. As an example, a "Pub-Sub" system may produce an event stream
222+
when "subscribing to a topic", with an event emitted for each "publish" to that
223+
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 may
227+
never complete. If an event stream encounters an error, it must complete with
228+
that error.
229+
230+
An observer may at any point decide to stop observing an event stream by
231+
cancelling it. When an event stream is cancelled, it must complete.
228232

229233
**Supporting Subscriptions at Scale**
230234

@@ -268,10 +272,10 @@ CreateSourceEventStream(subscription, schema, variableValues, initialValue):
268272
- Let {field} be the first entry in {fields}.
269273
- Let {argumentValues} be the result of {CoerceArgumentValues(subscriptionType,
270274
field, variableValues)}.
271-
- Let {fieldStream} be the result of running
275+
- Let {sourceStream} be the result of running
272276
{ResolveFieldEventStream(subscriptionType, initialValue, fieldName,
273277
argumentValues)}.
274-
- Return {fieldStream}.
278+
- Return {sourceStream}.
275279

276280
ResolveFieldEventStream(subscriptionType, rootValue, fieldName, argumentValues):
277281

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

293297
MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):
294298

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

302312
ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
303313

@@ -317,9 +327,9 @@ Note: The {ExecuteSubscriptionEvent()} algorithm is intentionally similar to
317327
#### Unsubscribe
318328

319329
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
322-
the subscription.
330+
receive payloads for a subscription. This in turn also cancels the Source
331+
Stream, which is a good opportunity to clean up any other resources used by the
332+
subscription.
323333

324334
Unsubscribe(responseStream):
325335

0 commit comments

Comments
 (0)