Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions yarn-project/foundation/src/promise/running-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class RunningPromise {
* Starts the running promise.
*/
public start() {
if (this.running) {
this.logger.warn(`Attempted to start running promise that was already started`);
return;
}
this.running = true;

const poll = async () => {
Expand Down Expand Up @@ -54,6 +58,10 @@ export class RunningPromise {
* and waits for the currently executing function to complete.
*/
async stop(): Promise<void> {
if (!this.running) {
this.logger.warn(`Running promise was not started`);
return;
}
this.running = false;
this.interruptibleSleep.interrupt();
await this.runningPromise;
Expand Down
5 changes: 5 additions & 0 deletions yarn-project/foundation/src/queue/serial_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FifoMemoryQueue } from './fifo_memory_queue.js';
export class SerialQueue {
private readonly queue = new FifoMemoryQueue<() => Promise<void>>();
private runningPromise!: Promise<void>;
private started = false;

/**
* Initializes the execution of enqueued functions in the serial queue.
Expand All @@ -14,7 +15,11 @@ export class SerialQueue {
* This method should be called once to start processing the queue.
*/
public start() {
if (this.started) {
return;
}
this.runningPromise = this.queue.process(fn => fn());
this.started = true;
}

/**
Expand Down