Skip to content

Commit d6a7067

Browse files
committed
Trigger subscriber after transaction is closed
1 parent bd4dd96 commit d6a7067

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/core-graph/src/private/Graph2.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class Graph2<TInput extends GraphNode, TOutput extends GraphNode = TInput> imple
7676

7777
this.#busy = true;
7878

79+
let record: GraphSubscriberRecord | undefined;
80+
7981
try {
8082
const getState = this.getState.bind(this);
8183
const upsertedNodes = new Map<Identifier, TInput>();
@@ -111,15 +113,17 @@ class Graph2<TInput extends GraphNode, TOutput extends GraphNode = TInput> imple
111113
this.#state = Object.freeze(nextState);
112114

113115
// After this line, there must be no more write operations on this object instance.
114-
const record = Object.freeze({ upsertedNodeIdentifiers: Object.freeze(upsertedNodeIdentifiers) });
115-
116-
for (const subscriber of this.#subscribers) {
117-
subscriber(record);
118-
}
116+
record = Object.freeze({ upsertedNodeIdentifiers: Object.freeze(upsertedNodeIdentifiers) });
119117
}
120118
} finally {
121119
this.#busy = false;
122120
}
121+
122+
if (record) {
123+
for (const subscriber of this.#subscribers) {
124+
subscriber(record);
125+
}
126+
}
123127
}
124128

125129
getState(): GraphState<TOutput> {

0 commit comments

Comments
 (0)