Skip to content

Commit 071438f

Browse files
Move notify await point
1 parent f54a0fa commit 071438f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/restate-sdk/src/context_impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,14 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
706706
await this.outputWriter.write(nextOutput);
707707
}
708708

709-
// Notify await point
710-
this.coreVm.notify_await_point(handle);
711-
712709
// Now loop waiting for the async result
713710
let asyncResult = this.coreVm.take_async_result(handle);
714711
while (asyncResult == "NotReady") {
715712
await this.awaitNextRead();
713+
// Using notify_await_point immediately before take_async_result
714+
// makes sure the state machine will try to suspend only now,
715+
// in case there aren't other concurrent tasks trying to poll this async result.
716+
this.coreVm.notify_await_point(handle);
716717
asyncResult = this.coreVm.take_async_result(handle);
717718
}
718719

0 commit comments

Comments
 (0)