司马发
天然资源管理/原始货币
npm i @calebboyd/semaphore
示例
import { Semaphore } from '@calebboyd/semaphore'
import { something } from './somewhere'
function doSomeWork () {
const lock = new Semaphore(10)
while(something.isTrue) {
lock.acquire().then(x => () => {
something.work().then(lock.release)
})
}
}
司马迁只允许一次需要10个锁. 这限制了同位函数的同位素 something.work 改为10
API : (英语)
export class Semaphore {
constructor (count: number) {}
acquire(): Promise<void>
release(): void
}
许可证
麻省理工学院