https://github.com/hieyou1/myturn
Super simple library to make sure Promises wait their turn to resolve.
https://github.com/hieyou1/myturn
async lock mutex myturn promise
Last synced: 2 months ago
JSON representation
Super simple library to make sure Promises wait their turn to resolve.
- Host: GitHub
- URL: https://github.com/hieyou1/myturn
- Owner: hieyou1
- License: mit
- Created: 2024-12-01T00:21:52.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-12-01T03:56:08.000Z (11 months ago)
- Last Synced: 2025-02-01T22:48:05.931Z (9 months ago)
- Topics: async, lock, mutex, myturn, promise
- Language: TypeScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# myturn
Super simple library to make sure Promises wait their turn to resolve. It's probably not best practice to use this library in production because it could negate the performance benefits of asynchronous code.
## Usage
```js
import { MyTurn } from "myturn";
let lock = new MyTurn();
console.log(lock.isLocked); // false
await lock.wait();
try {
// Something that really shouldn't be happening at the same time as another thing
console.log(lock.isLocked); // true
} finally {
lock.done();
}
console.log(lock.isLocked); // false
// Ready to be locked again!
```
## License
MIT