-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64c7acb
commit 0e55c2f
Showing
4 changed files
with
69 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import fullstore from 'fullstore'; | ||
|
||
const noop = () => {}; | ||
|
||
export const createIsStop = (parentPort) => { | ||
if (!parentPort) | ||
return noop; | ||
|
||
const isStop = fullstore(false); | ||
|
||
parentPort?.on('message', ([event]) => { | ||
if (event === 'stop') | ||
isStop(true); | ||
}); | ||
|
||
return isStop; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
test, | ||
stub, | ||
} from 'supertape'; | ||
import {createIsStop} from './is-stop.mjs'; | ||
|
||
test('putout: bin: isStop: parentPort', (t) => { | ||
const on = stub(); | ||
const parentPort = { | ||
on, | ||
}; | ||
|
||
const args = ['message', stub()]; | ||
|
||
createIsStop(parentPort); | ||
|
||
t.calledWith(on, args); | ||
t.end(); | ||
}); | ||
|
||
test('putout: bin: isStop: no parentPort', (t) => { | ||
const isStop = createIsStop(); | ||
const result = isStop(); | ||
|
||
t.notOk(result); | ||
t.end(); | ||
}); | ||
|
||
test('putout: bin: isStop: parentPort: isStop', (t) => { | ||
const on = stub(); | ||
const parentPort = { | ||
on, | ||
}; | ||
|
||
const isStop = createIsStop(parentPort); | ||
const [args] = on.args; | ||
const [, listener] = args; | ||
|
||
listener(['stop']); | ||
|
||
const result = isStop(); | ||
|
||
t.ok(result); | ||
t.end(); | ||
}); |
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