Skip to content

Commit a477be4

Browse files
Disable suspensions in Embedded handler (#172)
1 parent 19c0979 commit a477be4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/embedded/invocation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export const doInvoke = async <I, O>(
6060
const stateMachine = new StateMachine(
6161
connection,
6262
journal,
63-
ProtocolMode.BIDI_STREAM
63+
ProtocolMode.BIDI_STREAM,
64+
-1
6465
);
6566

6667
//

src/state_machine.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ export class StateMachine<I, O> implements RestateStreamConsumer {
5858
// Suspension timeout that gets set and cleared based on completion messages;
5959
private suspensionTimeout?: NodeJS.Timeout;
6060

61-
private readonly suspensionMillis = 30_000;
62-
6361
constructor(
6462
private readonly connection: Connection,
6563
private readonly invocation: Invocation<I, O>,
66-
private readonly protocolMode: ProtocolMode
64+
private readonly protocolMode: ProtocolMode,
65+
private readonly suspensionMillis: number = 30_000
6766
) {
6867
this.localStateStore = invocation.localStateStore;
6968

@@ -383,11 +382,15 @@ export class StateMachine<I, O> implements RestateStreamConsumer {
383382
"Scheduling suspension in " + delay + " ms"
384383
);
385384

386-
// Set a new suspension with a new timeout
387-
// The suspension will only be sent if the timeout is not canceled due to a completion.
388-
this.suspensionTimeout = setTimeout(() => {
389-
this.suspend();
390-
}, delay);
385+
if (delay >= 0) {
386+
// Set a new suspension with a new timeout
387+
// The suspension will only be sent if the timeout is not canceled due to a completion.
388+
// In case the delay is 0 we still schedule a timeout in order to process the suspension on the next process tick,
389+
// without interrupting the current work.
390+
this.suspensionTimeout = setTimeout(() => {
391+
this.suspend();
392+
}, delay);
393+
}
391394
}
392395

393396
// Suspension timeouts:

0 commit comments

Comments
 (0)