Files: eb6fd4434e06cb5f0151897c665d531a4c84151e / tests / index.js
550 bytesRaw
1 | const tape = require('tape') |
2 | const LockMap = require('../') |
3 | |
4 | tape('lockmap tests', async t => { |
5 | t.plan(4) |
6 | // create a new lock map |
7 | const lockmap = new LockMap() |
8 | t.equals(lockmap.toString(), '[object LockMap]') |
9 | const id = 'test' |
10 | |
11 | let first = true |
12 | |
13 | // set a lock for an id |
14 | const unlock = lockmap.lock(id) |
15 | |
16 | setTimeout(() => { |
17 | // do some async work |
18 | t.equals(first, true) |
19 | first = false |
20 | unlock() |
21 | }, 300) |
22 | |
23 | t.equals(lockmap.size, 1) |
24 | |
25 | // wait until the lock resolves |
26 | await lockmap.get(id) |
27 | t.equals(first, false) |
28 | }) |
29 |
Built with git-ssb-web