The number of permits the semaphore has.
A new Semaphore instance.
const semaphore = newSemaphore(2);
// Acquire a permit manually
const permit = await semaphore.acquire();
try {
// Critical section - permit is automatically managed
await fetch('/api/data');
} finally {
permit.release();
}
// Or use with automatic resource management
await using permit = await semaphore.acquire();
// Critical section - permit automatically released at end of scope
await fetch('/api/data');
// Or use the run helper
await semaphore.run(async () => {
// Critical section - permit automatically managed
return await fetch('/api/data');
});
Creates a new Semaphore with the given number of permits.