-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP on a file budget * Add a filesystem budget This adds a wrapper around the 'fs/promises' module that will limit parallelism of filesystem operations. Larger projects (e.g. monorepos) have had crashes that look like file descriptor exhaustion. * Fix lint, minor cleanup. * Add test, pick better names, add Sempahore class * lint and format * Revert package-lock changes * Revert typescript version. * Changelog * Add license Co-authored-by: Al Marks <aomarks@gmail.com> * Add license Co-authored-by: Al Marks <aomarks@gmail.com> * Update README.md Co-authored-by: Al Marks <aomarks@gmail.com> * Format README --------- Co-authored-by: Al Marks <aomarks@gmail.com>
- Loading branch information
Showing
18 changed files
with
362 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"javascript.preferences.importModuleSpecifierEnding": "js", | ||
"typescript.preferences.importModuleSpecifierEnding": "js", | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"typescript.tsdk": "node_modules\\typescript\\lib", | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} |
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
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
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,42 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {Semaphore} from '../util/fs.js'; | ||
import {test} from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
async function wait(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
test('Semaphore restricts resource access', async () => { | ||
const semaphore = new Semaphore(1); | ||
const reservation1 = await semaphore.reserve(); | ||
const reservation2Promise = semaphore.reserve(); | ||
let hasResolved = false; | ||
void reservation2Promise.then(() => { | ||
hasResolved = true; | ||
}); | ||
// Wait a bit to make sure the promise has had a chance to resolve. | ||
await wait(100); | ||
// The semaphore doesn't let the second reservation happen yet, it would | ||
// be over budget. | ||
assert.is(hasResolved, false); | ||
reservation1[Symbol.dispose](); | ||
// Now it can happen. | ||
await reservation2Promise; | ||
assert.is(hasResolved, true); | ||
}); | ||
|
||
test('Semaphore reservation happens immediately when not under contention', async () => { | ||
const semaphore = new Semaphore(3); | ||
await semaphore.reserve(); | ||
await semaphore.reserve(); | ||
await semaphore.reserve(); | ||
// If the test finishes, then we were able to reserve three slots. | ||
}); | ||
|
||
test.run(); |
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
Oops, something went wrong.