git ssb

0+

wanderer🌟 / lockmap



Tree: 9b184c558e4d613077feb2d574d22cdbcdde797c

Files: 9b184c558e4d613077feb2d574d22cdbcdde797c / tests / index.js

550 bytesRaw
1const tape = require('tape')
2const LockMap = require('../')
3
4tape('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