Skip to content

Commit 29764c3

Browse files
committed
feat(shell-api): add checkpoint method to InterruptFlag
1 parent 3f1513b commit 29764c3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/shell-api/src/interruptor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ export class InterruptFlag {
2121
return this.interrupted;
2222
}
2323

24+
/**
25+
* Perform a checkpoint; reject immediately if an interruption has already
26+
* occurred, and resolve immediately otherwise. This is useful to insert
27+
* in operations consisting of multiple asynchronous steps.
28+
*/
29+
public async checkpoint(): Promise<void> {
30+
if (this.interrupted) {
31+
await this.asPromise().promise;
32+
}
33+
}
34+
2435
/**
2536
* The returned promise will never be resolved but is rejected
2637
* when the interrupt is set. The rejection happens with an

packages/shell-evaluator/src/shell-evaluator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ class ShellEvaluator<EvaluationResultType = ShellResult> {
6363
rewrittenInput = supportCode + ';\n' + rewrittenInput;
6464
}
6565

66-
return await originalEval(rewrittenInput, context, filename);
66+
try {
67+
return await originalEval(rewrittenInput, context, filename);
68+
} catch (err) {
69+
throw this.internalState.transformError(err);
70+
}
6771
}
6872

6973
/**

0 commit comments

Comments
 (0)