-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass filename and options from Thread to Worker
Refs: #416
- Loading branch information
1 parent
c196045
commit 161590c
Showing
2 changed files
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
'use strict'; | ||
|
||
const { isMainThread } = require('worker_threads'); | ||
const { locks } = require('..'); | ||
const { Thread } = locks; | ||
const metatests = require('metatests'); | ||
const common = require('@metarhia/common'); | ||
const nodeVerion = common.between(process.version, 'v', '.'); | ||
|
||
const sleep = msec => | ||
new Promise(resolve => { | ||
setTimeout(resolve, msec); | ||
}); | ||
if (nodeVerion >= 11) { | ||
const { isMainThread } = require('worker_threads'); | ||
const { locks } = require('..'); | ||
const { Thread } = locks; | ||
const metatests = require('metatests'); | ||
|
||
if (isMainThread) { | ||
metatests.test('locks: enter and leave', test => { | ||
new Thread(); | ||
new Thread(); | ||
const sleep = msec => | ||
new Promise(resolve => { | ||
setTimeout(resolve, msec); | ||
}); | ||
|
||
setTimeout(() => { | ||
locks.request('A', async lock => { | ||
test.end(); | ||
}); | ||
}, 100); | ||
}); | ||
} else { | ||
locks.request('A', async lock => { | ||
await sleep(100); | ||
}); | ||
if (isMainThread) { | ||
metatests.test('locks: enter and leave', test => { | ||
new Thread(__filename); | ||
new Thread(__filename); | ||
|
||
setTimeout(() => { | ||
locks.request('A', async lock => { | ||
test.end(); | ||
}); | ||
}, 100); | ||
}); | ||
} else { | ||
locks.request('A', async lock => { | ||
await sleep(100); | ||
}); | ||
} | ||
} |