Skip to content

Commit 5ce2e7c

Browse files
committed
Tighten up update handler entry access
1 parent 5d4caca commit 5ce2e7c

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

packages/workflow/src/internals.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,9 @@ export class Activator implements ActivationHandler {
662662
// These are caught elsewhere and fail the corresponding activation.
663663
const doUpdateImpl = async () => {
664664
let input: UpdateInput;
665+
const entry = this.updateHandlers.get(name);
665666
try {
666-
if (runValidator && this.updateHandlers.get(name)?.validator) {
667+
if (runValidator && entry?.validator) {
667668
const validate = composeInterceptors(
668669
this.interceptors.inbound,
669670
'validateUpdate',
@@ -676,15 +677,12 @@ export class Activator implements ActivationHandler {
676677
this.rejectUpdate(protocolInstanceId, error);
677678
return;
678679
}
679-
680-
const entry = this.updateHandlers.get(name);
680+
this.acceptUpdate(protocolInstanceId);
681+
const execute = composeInterceptors(this.interceptors.inbound, 'handleUpdate', this.updateNextHandler.bind(this));
681682
if (!entry) {
682683
return Promise.reject(new IllegalStateError(`No registered update handler for update: ${name}`));
683684
}
684685
const { unfinishedPolicy } = entry;
685-
686-
const execute = composeInterceptors(this.interceptors.inbound, 'handleUpdate', this.updateNextHandler.bind(this));
687-
this.acceptUpdate(protocolInstanceId);
688686
this.inProgressUpdates.set(updateId, { name, unfinishedPolicy, id: updateId });
689687
const res = execute(input)
690688
.then((result) => this.completeUpdate(protocolInstanceId, result))
@@ -703,11 +701,7 @@ export class Activator implements ActivationHandler {
703701
}
704702

705703
protected async updateNextHandler({ name, args }: UpdateInput): Promise<unknown> {
706-
const entry = this.updateHandlers.get(name);
707-
if (!entry) {
708-
return Promise.reject(new IllegalStateError(`No registered update handler for update: ${name}`));
709-
}
710-
const { handler } = entry;
704+
const { handler } = this.updateHandlers.get(name)!;
711705
return await handler(...args);
712706
}
713707

0 commit comments

Comments
 (0)