git ssb

0+

wanderer🌟 / lockmap



Tree: d875b8b05b237bdbe18027c2d27eb7ff8197110e

Files: d875b8b05b237bdbe18027c2d27eb7ff8197110e / tests / index.js

474 bytesRaw
1const tape = require('tape')
2const LockMap = require('../')
3
4tape('lockmap tests', async t => {
5 t.plan(2)
6 // create a new lock map
7 const lockmap = new LockMap()
8 const id = 'test'
9
10 let first = true
11
12 // set a lock for an id
13 const unlock = lockmap.lock(id)
14
15 setTimeout(() => {
16 // do some async work
17 t.equals(first, true)
18 first = false
19 unlock()
20 }, 300)
21
22 // wait until the lock resolves
23 await lockmap.getLock(id)
24 t.equals(first, false)
25})
26

Built with git-ssb-web