Skip to content

Commit

Permalink
Simple test for Web Locks API
Browse files Browse the repository at this point in the history
Refs: #416
  • Loading branch information
tshemsedinov committed Apr 8, 2019
1 parent aa2f980 commit d30af90
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/locks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const { isMainThread } = require('worker_threads');
const { locks } = require('..');
const { Thread } = locks;
const metatests = require('metatests');

const sleep = msec =>
new Promise(resolve => {
setTimeout(resolve, msec);
});

if (isMainThread) {
metatests.test('locks: enter and leave', test => {
new Thread();
new Thread();

setTimeout(() => {
locks.request('A', async lock => {
test.end();
});
}, 100);
});
} else {
locks.request('A', async lock => {
await sleep(100);
});
}

0 comments on commit d30af90

Please sign in to comment.