securityos/node_modules/sync-channel/test.js

33 lines
653 B
JavaScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
var SyncChannel = require('./SyncChannel');
function test1() {
var channel = new SyncChannel();
function thread1() {
function loop() {
channel.read(function (value) {
if (value % 1000 === 0) {
console.log(value);
}
loop();
});
}
loop();
}
function thread2() {
var n = 0;
function loop() {
channel.write(n, function () {
n++;
loop();
});
}
loop();
}
thread1();
thread2();
}
test1();