Skip to content

Commit 6c03c99

Browse files
authored
Some UX polish for enabling/disabling functions (#3203)
1 parent 863786a commit 6c03c99

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixes extra logging and race conditions when disabling emulated background functions.

src/emulator/functionsEmulator.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,9 @@ export class FunctionsEmulator implements EmulatorInstance {
876876
return this.workerPool.submitWork(frb.triggerId, frb, opts);
877877
}
878878

879-
disableBackgroundTriggers() {
879+
async disableBackgroundTriggers() {
880880
Object.values(this.triggers).forEach((record) => {
881-
if (record.def.eventTrigger) {
881+
if (record.def.eventTrigger && record.enabled) {
882882
this.logger.logLabeled(
883883
"BULLET",
884884
`functions[${record.def.entryPoint}]`,
@@ -887,6 +887,8 @@ export class FunctionsEmulator implements EmulatorInstance {
887887
record.enabled = false;
888888
}
889889
});
890+
891+
await this.workQueue.flush();
890892
}
891893

892894
async reloadTriggers() {

src/emulator/hub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class EmulatorHub implements EmulatorInstance {
104104
}
105105
});
106106

107-
this.hub.put(EmulatorHub.PATH_DISABLE_FUNCTIONS, (req, res) => {
107+
this.hub.put(EmulatorHub.PATH_DISABLE_FUNCTIONS, async (req, res) => {
108108
utils.logLabeledBullet(
109109
"emulators",
110110
`Disabling Cloud Functions triggers, non-HTTP functions will not execute.`
@@ -117,7 +117,7 @@ export class EmulatorHub implements EmulatorInstance {
117117
}
118118

119119
const emu = instance as FunctionsEmulator;
120-
emu.disableBackgroundTriggers();
120+
await emu.disableBackgroundTriggers();
121121
res.status(200).json({ enabled: false });
122122
});
123123

0 commit comments

Comments
 (0)