From 906af889d91808a798b046631d30afeff5b1c9a7 Mon Sep 17 00:00:00 2001 From: johnnyman727 Date: Sat, 3 May 2014 12:04:56 -0700 Subject: [PATCH] Moved queue code into npm module so it can be used for other modules --- index.js | 4 ++-- lib/simple-queue.js | 34 ---------------------------------- package.json | 3 +++ 3 files changed, 5 insertions(+), 36 deletions(-) delete mode 100644 lib/simple-queue.js diff --git a/index.js b/index.js index 600682d..ddd2c3c 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ var util = require('util'); var EventEmitter = require('events').EventEmitter; -var q = require('./lib/simple-queue'); +var queue = require('sync-queue'); // The SparkFun breakout board defaults to 1, set to 0 if SA0 jumper on the bottom of the board is set var I2C_ADDRESS = 0x1D; // 0x1D if SA0 is high, 0x1C if low @@ -18,7 +18,7 @@ function Accelerometer (hardware, callback) { var self = this; // Command Queue - self.queue = q.createQueue(); + self.queue = new queue(); // Port assignment self.hardware = hardware; // Rate at which data is collected and is ready to be read diff --git a/lib/simple-queue.js b/lib/simple-queue.js deleted file mode 100644 index d9a79f8..0000000 --- a/lib/simple-queue.js +++ /dev/null @@ -1,34 +0,0 @@ -function createQueue() { - - // Create an empty array of commands - var queue = []; - // We're inactive to begin with - queue.active = false; - // Method for adding command chain to the queue - queue.place = function (command) { - // Push the command onto the command array - queue.push(command); - // If we're currently inactive, start processing - if (!queue.active) queue.next(); - }; - // Method for calling the next command chain in the array - queue.next = function () { - // If this is the end of the queue - if (!queue.length) { - // We're no longer active - queue.active = false; - // Stop execution - return; - } - // Grab the next command - var command = queue.shift(); - // We're active - queue.active = true; - // Call the command - command(); - }; - - return queue; -} - -module.exports.createQueue = createQueue; \ No newline at end of file diff --git a/package.json b/package.json index f2cbcb8..6eb17ce 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "dependencies" : { + "sync-queue" : "*" + }, "hardware": { "./examples": false },