Skip to content

Commit d30af90

Browse files
committed
Simple test for Web Locks API
Refs: #416
1 parent aa2f980 commit d30af90

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/locks.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const { isMainThread } = require('worker_threads');
4+
const { locks } = require('..');
5+
const { Thread } = locks;
6+
const metatests = require('metatests');
7+
8+
const sleep = msec =>
9+
new Promise(resolve => {
10+
setTimeout(resolve, msec);
11+
});
12+
13+
if (isMainThread) {
14+
metatests.test('locks: enter and leave', test => {
15+
new Thread();
16+
new Thread();
17+
18+
setTimeout(() => {
19+
locks.request('A', async lock => {
20+
test.end();
21+
});
22+
}, 100);
23+
});
24+
} else {
25+
locks.request('A', async lock => {
26+
await sleep(100);
27+
});
28+
}

0 commit comments

Comments
 (0)