Skip to content

Commit ffd7644

Browse files
committed
Refactor floating string.
1 parent cec9d2c commit ffd7644

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Refactor the way timeouts are enforced by the Functions Emulator (#5464)

src/emulator/functionsRuntimeWorker.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export enum RuntimeWorkerState {
2929
FINISHED = "FINISHED",
3030
}
3131

32+
/**
33+
* Given no trigger key, worker is given this special key.
34+
*
35+
* This is useful when running the Functions Emulator in debug mode
36+
* where single process shared amongst all triggers.
37+
*/
38+
const FREE_WORKER_KEY = "~free~";
39+
3240
export class RuntimeWorker {
3341
readonly id: string;
3442
readonly triggerKey: string;
@@ -46,7 +54,7 @@ export class RuntimeWorker {
4654
readonly timeoutSeconds?: number
4755
) {
4856
this.id = uuid.v4();
49-
this.triggerKey = triggerId || "~free~";
57+
this.triggerKey = triggerId || FREE_WORKER_KEY;
5058
this.runtime = runtime;
5159

5260
const childProc = this.runtime.process;
@@ -118,14 +126,14 @@ export class RuntimeWorker {
118126
}
119127

120128
request(req: http.RequestOptions, resp: http.ServerResponse, body?: unknown): Promise<void> {
121-
if (this.triggerKey !== "~free~") {
129+
if (this.triggerKey !== FREE_WORKER_KEY) {
122130
this.logInfo(`Beginning execution of "${this.triggerKey}"`);
123131
}
124132
const startHrTime = process.hrtime();
125133

126134
this.state = RuntimeWorkerState.BUSY;
127135
const onFinish = (): void => {
128-
if (this.triggerKey !== "~free~") {
136+
if (this.triggerKey !== FREE_WORKER_KEY) {
129137
const elapsedHrTime = process.hrtime(startHrTime);
130138
this.logInfo(
131139
`Finished "${this.triggerKey}" in ${

0 commit comments

Comments
 (0)