Skip to content

Commit

Permalink
Merge pull request #7 from tungs/0.2.1-release
Browse files Browse the repository at this point in the history
0.2.1 release
  • Loading branch information
tungs authored Feb 27, 2017
2 parents 82d92c3 + 9482422 commit 26e7c6e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
31 changes: 23 additions & 8 deletions breathe.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
**********************/

var breathe = {
version: '0.2.0'
version: '0.2.1'
};

/**********************
Expand Down Expand Up @@ -361,6 +361,26 @@
}
};

var customHandlers = {};
breathe.on = function (type, fn) {
customHandlers[type] = customHandlers[type] || [];
customHandlers[type].push(fn);
};
var trigger = function (type, data) {
var i;
var handlers = customHandlers[type];
if (!handlers) {
return;
}
for (i=0; i < handlers.length; i++) {
if (data) {
handlers[i].apply(this, data);
} else {
handlers[i]();
}
}
};

/**********************
* Main loop
**********************/
Expand All @@ -373,10 +393,10 @@
var doSomeWork = function () {
var start = timer.now();
var ind;
var item;
var id;
var throttleCount = {};
_inMainLoop = true;
trigger('batchBegin');
if (_workTimeouter.prework) {
_workTimeoutRef = _workTimeouter.prework(doSomeWork);
}
Expand Down Expand Up @@ -425,6 +445,7 @@
_workTimeoutRef = _workTimeouter.postwork(doSomeWork);
}
_currWorkId = GENERAL_WORK_ID;
trigger('batchEnd');
_inMainLoop = false;
};
// Start the main loop, even though there are no items in any of the queues
Expand Down Expand Up @@ -582,9 +603,6 @@
var id = _currWorkId;
var currVal;
var stateHandler = new StateHandler();
var callGate;
var pauser;
var pauseGate;

var atEnd = function() {
return endPromise.state === promiseStates.resolved
Expand Down Expand Up @@ -659,9 +677,6 @@
var condition = config.condition;
var currVal = config.initVal;
var stateHandler = new StateHandler();
var callGate;
var pauseGate;
var pauser;
var retLoop = breatheChain(function (resolve, reject) {
var workBit;
var preworkBit;
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./breathe.js');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breathejs",
"version": "0.2.0",
"version": "0.2.1",
"description": "a library to write nonblocking, asynchronous JavaScript",
"license": "BSD-3-Clause",
"homepage": "https://breathejs.org",
Expand Down
8 changes: 5 additions & 3 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ var blockingRecursiveChain = function (remaining, fn) {

var blockingChain = function (time) {
return breathe.chain(function (resolve, reject) {
var i=0;
var start = getMilliseconds();
while (getMilliseconds() - start < time) {
// wait
i++;
}
resolve();
});
Expand Down Expand Up @@ -218,7 +220,7 @@ describe('`breathe`', function () {


it('should not immediately run', function () {
var i, c = initValue;
var i = 0, c = initValue;
var loop = breathe.loop(function () {
return i < testIterations;
}, function () {
Expand Down Expand Up @@ -258,7 +260,7 @@ describe('`breathe`', function () {
var v = initValue;
var i = 0;
var ret = breathe.loop(function () {
return i < 100;
return i < 200;
}, function () {
i++;
return blockingChain(1);
Expand All @@ -276,7 +278,7 @@ describe('`breathe`', function () {
var v = initValue;
var i = 0;
var ret = breathe.loop(function () {
return i < 100;
return i < 200;
}, function () {
i++;
return blockingChain(1);
Expand Down

0 comments on commit 26e7c6e

Please sign in to comment.