-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.js
More file actions
45 lines (35 loc) · 927 Bytes
/
Copy pathclient.js
File metadata and controls
45 lines (35 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { FileMapping, Mutex } = require('./build/Release/addon');
map = new FileMapping();
lock = new Mutex();
async function waitFor(ms) {
return new Promise(function (resolve, reject) {
setTimeout(function() {
return resolve();
}, ms);
});
}
function main() {
return new Promise(async function(resolve, reject) {
buffer = Buffer.alloc(4) // 4 byte buffer to write to a 4 byte shared storage
map.openMapping('howard_mem_map', 4)
lock.open('howard_mem_map_lock');
for (var i = 0; i < 60; ++i)
{
// Wait 1 second between changes
await waitFor(10);
// Write the new value
buffer.writeInt32LE(i);
lock.wait();
map.writeBuffer(buffer, 0, 0, 4);
lock.release();
console.log('Wrote ' + i);
}
map.closeMapping()
lock.close();
resolve();
})
}
mainPromise = main()
mainPromise.then(function() {
console.log('End!')
});