Skip to content

Commit 385d9c5

Browse files
committed
since only uses of forEachWithCB are getStates and setStates, use that as a mutex point to avoid race between two setStates calls. fixes #2
1 parent b2f25fa commit 385d9c5

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
var q = require('queue-async'),
2+
fifo = require('fifolock'),
23
stream = require('stream'),
34
util = require('util'),
45
events = require('events'),
56
SPI = require('pi-spi'),
67
GPIO = require('pi-pins'),
78
_m = require("./magicnums");
89

9-
function forEachWithCB(fn, cb) {
10+
var mutex = fifo(); // HACK: avoid https://github.com/natevw/node-nrf/commit/8d80dabde1026e949f4eb4ea6d25624cbf3c70ec
11+
function forEachWithCB(fn, cb) { cb = mutex.TRANSACTION_WRAPPER(cb, function () {
1012
var process = q(1);
1113
this.forEach(function (d) { process.defer(fn, d); });
1214
process.awaitAll(cb);
13-
};
15+
}.bind(this)); }
1416

1517
function _extend(obj) {
1618
for (var i = 1, len = arguments.length; i < len; i++) {

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
"url": "https://github.com/natevw/node-nrf/issues"
2525
},
2626
"dependencies": {
27+
"fifolock": "^1.0.0",
28+
"pi-pins": "^1.0.0",
2729
"pi-spi": "~0.8.1",
28-
"queue-async": "~1.0.4",
29-
"pi-pins": "^1.0.0"
30+
"queue-async": "~1.0.4"
3031
}
3132
}

0 commit comments

Comments
 (0)