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 Mar 27, 2019
1 parent 6cea327 commit 20354f8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/locks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'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 20354f8

Please sign in to comment.