Skip to content

Commit 3768025

Browse files
committed
initialize only after yielding
1 parent 894b994 commit 3768025

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

spec/Section 6 -- Execution.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,29 @@ serial):
726726
- Let {initialFuture} be the future result of
727727
{ExecuteInitialResult(variableValues, initialValue, objectType, selectionSet,
728728
serial)}.
729-
- Initialize {pendingResults}, {pendingFutures}, and {unsent} to the empty set.
729+
- Initiate {initialFuture}.
730+
- Initialize {pendingFutures} to a set containing {initialFuture}.
731+
- Initialize {pendingResults} {pendingFutures}, and {unsent} to the empty set.
730732
- Initialize {newPendingResultsByFragment}, {pendingFuturesByFragment}, and
731733
{completedFuturesByFragment} to empty unordered maps.
732734
- Repeat the following steps:
733-
- Initialize {pending}, {incremental}, and {completed} to empty lists.
734-
- Wait for any futures within {pendingFutures} to complete.
735-
- Let {completedFutures} be those completed futures.
735+
- If none of the futures in {pendingFutures} have completed:
736+
- If {incremental} or {completed} is not empty:
737+
- If {pendingResults} is empty, let {hasNext} be {false}, otherwise let it
738+
be {true}.
739+
- Let {incrementalResult} be a new unordered map containing {pending},
740+
{incremental}, {completed} and {hasNext}.
741+
- Yield {incrementalResult}.
742+
- If {hasNext} is {false}, complete this incremental result stream and
743+
return.
744+
- For each {future} in {newFutures}:
745+
- Initialize {future} if it has not yet been initialized.
746+
- Add {future} to {pendingFutures}.
747+
- Reset {newFutures} to the empty set.
748+
- Reset {pending}, {incremental}, and {completed} to empty lists.
749+
- Wait for any futures within {pendingFutures} to complete.
750+
- Let {completedFutures} be the futures in {pendingFutures} that have
751+
completed.
736752
- For each {future} in {completedFutures}:
737753
- Remove {future} from {pendingFutures}.
738754
- Let {result} be the result of {future}.
@@ -778,12 +794,12 @@ serial):
778794
in {pendingFuturesByFragment}.
779795
- If the size of {completedFuturesForFragment} is equal to the size of
780796
{pendingFuturesForFragment}:
781-
- Let {fragmentPendingFutures}, {fragmentPending},
797+
- Let {fragmentNewFutures}, {fragmentPending},
782798
{fragmentIncremental}, and {fragmentCompleted}, be the result of
783799
{CompleteFragment(deferredFragment, completedFuturesForFragment,
784800
pendingFuturesForFragment, newPendingResultsByFragment,
785801
completedFuturesByFragment, unsent)}.
786-
- Add all items in {fragmentPendingFutures} to {pendingFutures}.
802+
- Add all items in {fragmentNewFutures} to {newFutures}.
787803
- For each {pendingResult} in {fragmentPending}:
788804
- Append {pendingResult} to {pending}.
789805
- Add {pendingResult} to {pendingResults}.
@@ -796,10 +812,9 @@ serial):
796812
- For each {result} in {incremental}:
797813
- Let {newPendingResults} and {futures} be the corresponding entries on
798814
{incremental}.
799-
- For each {future} of {futures}:
800-
- If {future} represents completion of Stream Items:
801-
- Initiate {future} if it has not yet been initiated.
802-
- Add {future} to {pendingFutures}.
815+
- For each {future} of {futures}: If {future} represents completion of
816+
Stream Items:
817+
- Add {future} to {newFutures}.
803818
- Otherwise:
804819
- Let {deferredFragments} be the Deferred Fragments completed by
805820
{future}.
@@ -809,8 +824,7 @@ serial):
809824
exists, create it as an empty list.
810825
- Append {future} to {pendingFuturesForFragment}.
811826
- If {deferredFragment} is contained by {pendingResults}:
812-
- Initiate {future} if it has not yet been initiated.
813-
- Add {future} to {pendingFutures}.
827+
- Add {future} to {newFutures}.
814828
- For each {newPendingResult} of {newPendingResults}:
815829
- If {newPendingResult} represents a Stream:
816830
- Append {newPendingResult} to {pending}.
@@ -825,25 +839,12 @@ serial):
825839
- Append {newPendingResult} to {pending}.
826840
- Add {newPendingResult} to {pendingResults}.
827841
- For each {future} in {pendingFuturesForFragment}:
828-
- Initiate {future} if it has not yet been initiated.
829-
- Add {future} to {pendingFutures}.
842+
- Add {future} to {newFutures}.
830843
- Otherwise:
831844
- Let {newPendingResultsForFragment} be the entry for {parent} in
832845
{newPendingResultsByFragment}; if no such list exists, create it
833846
as an empty list.
834847
- Append {newPendingResult} to {newPendingResultsForFragment}.
835-
- If {pendingResults} is empty, let {hasNext} be {false}, otherwise let it
836-
be {true}.
837-
- If {data} is defined:
838-
- Let {incrementalResult} be a new unordered map containing {data},
839-
{errors} and {pending}.
840-
- Yield {incrementalResult}.
841-
- Otherwise, if {incremental} or {completed} is not empty:
842-
- Let {incrementalResult} be a new unordered map containing {pending},
843-
{incremental}, {completed} and {hasNext}.
844-
- Yield {incrementalResult}.
845-
- If {hasNext} is {false}, complete this incremental result stream and
846-
return.
847848

848849
ExecuteInitialResult(variableValues, initialValue, objectType, selectionSet,
849850
serial):
@@ -865,7 +866,7 @@ CompleteFragment(deferredFragment, completedFuturesForFragment,
865866
pendingFuturesForFragment, newPendingResultsByFragment,
866867
completedFuturesByFragment, unsent):
867868

868-
- Initialize {pendingFutures} to the empty set.
869+
- Initialize {newFutures} to the empty set.
869870
- Initialize {pending}, {incremental}, and {completed} to empty lists.
870871
- Let {completedEntry} be an empty unordered map.
871872
- Set the entry for {pendingResult} on {completedEntry} to {deferredFragment}.
@@ -889,16 +890,15 @@ completedFuturesByFragment, unsent):
889890
{fragmentCompleted}, be the result of {CompleteFragment(deferredFragment,
890891
resultsForFragment, pendingFuturesForFragment,
891892
newPendingResultsByFragment, resultsByFragment, unsent)}.
892-
- Add all items in {fragmentPendingFutures} to {pendingFutures}.
893+
- Add all items in {fragmentNewFutures} to {newFutures}.
893894
- Append all items in {fragmentPending} to {pending}.
894895
- Append all items in {fragmentIncremental} to {incremental}.
895896
- Append all items in {fragmentCompleted} to {completed}.
896897
- Otherwise:
897898
- For each {future} in {fragmentPendingFuturesForFragment}:
898899
- If {completedFuturesForFragment} does not contain {future}:
899-
- Initiate {future} if it has not yet been initiated.
900-
- Add {future} to {pendingFutures}.
901-
- Return {pendingFutures}, {pending}, {incremental}, and {completed}.
900+
- Add {future} to {newFutures}.
901+
- Return {newFutures}, {pending}, {incremental}, and {completed}.
902902

903903
## Executing a Field Plan
904904

0 commit comments

Comments
 (0)