-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from depot/optimize-reconcile
- Loading branch information
Showing
4 changed files
with
61 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {reportError} from './errors' | ||
|
||
const inProgressTasks = new Set<string>() | ||
|
||
/** | ||
* Schedule an update to run, ensuring that only one update is running at a time. | ||
*/ | ||
export async function scheduleTask(key: string, task: () => Promise<void>) { | ||
if (inProgressTasks.has(key)) { | ||
console.log(`Skipping ${key} because it is already in progress`) | ||
return | ||
} | ||
|
||
try { | ||
inProgressTasks.add(key) | ||
console.log(`Accepted ${key}, starting task`) | ||
return await task() | ||
} catch (err) { | ||
await reportError(err) | ||
} finally { | ||
inProgressTasks.delete(key) | ||
console.log(`Task ${key} completed`) | ||
} | ||
} |