Skip to content

Commit

Permalink
Enforce a true l8 singleton (browserify get confused by symblinks som…
Browse files Browse the repository at this point in the history
…etimes). Fix missing 'new' for Promise. Fix a bug with water errors not properly built/detected
  • Loading branch information
JeanHuguesRobert committed Feb 3, 2015
1 parent 9c2d155 commit 304d455
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
l8 0.3.3
l8 0.3.6
========

[![Build Status](https://travis-ci.org/JeanHuguesRobert/l8.png)](https://travis-ci.org/JeanHuguesRobert/l8)
Expand Down
26 changes: 19 additions & 7 deletions lib/l8.js
Expand Up @@ -10,6 +10,13 @@

"use strict";

// There should be single l8 object, application wide. A true singleton.
var l8;
if( global.l8 ){
l8 = global.l8;
}else{


/* ----------------------------------------------------------------------------
* Debug. The one painful thing that we want to cure.
*/
Expand Down Expand Up @@ -155,7 +162,7 @@ var de = DEBUG, bug = trace, mand = assert

var NextTaskId = 0

function Task(){
var Task = function f_Task(){
// Tasks are like function call activation records, but with a spaghetti stack
// because more than one child task can be active at the same time.
// See also http://en.wikipedia.org/wiki/Spaghetti_stack
Expand Down Expand Up @@ -255,7 +262,7 @@ var task_init = function( task, parent, is_fork, is_spawn ){
if( TraceStartTask && NextTaskId > TraceStartTask )trace( "New", task)
}

function Step(){
var Step = function f_Step(){
// Tasks execute steps, some steps may queue additional steps to execute.
// Forked steps run in parallel whereas regular steps are sequential. Steps
// that cannot execute immediately can block and terminate later when some
Expand All @@ -271,7 +278,7 @@ var ProtoStep = Step.prototype

var NextFreeStep = null

function MakeStep( task, block, is_fork, is_repeat ){
var MakeStep = function l8_MakeStep( task, block, is_fork, is_repeat ){
var step = NextFreeStep
if( step ){
NextFreeStep = step.next
Expand Down Expand Up @@ -331,7 +338,8 @@ var step_init = function( step, task, block, is_fork, is_repeat ){
}

// Bootstrap root task, id 0
var l8 = MakeTask( {}/*dummy parent*/ )
var l8 = new Task();
task_init( l8, {} /*dummy parent*/ );
l8.parentTask = null
l8.data = {task:l8}

Expand Down Expand Up @@ -1040,7 +1048,7 @@ ProtoTask.__defineGetter__( "flow", function(){

var NextFreeTask = null

function MakeTask( parent, is_fork, is_spawn ){
var MakeTask = function f_MakeTask( parent, is_fork, is_spawn ){
var task = NextFreeTask
if( task ){
NextFreeTask = task.nextFree
Expand Down Expand Up @@ -1577,7 +1585,7 @@ ProtoTask.success = function( block ){
* Promise
*/

function Promise(){
var Promise = function f_Promise(){
// Promise/A compliant. See https://gist.github.com/3889970
this.wasResolved = false
this.resolveValue = void null
Expand All @@ -1589,7 +1597,7 @@ function Promise(){

var ProtoPromise = Promise.prototype

function MakePromise(){
var MakePromise = function MakePromise(){
return new Promise()
}

Expand Down Expand Up @@ -2101,4 +2109,8 @@ l8.countdown = function( n, silent ){
)
}

// Export true singleton
global.l8 = l8;
}

module.exports = l8;
9 changes: 6 additions & 3 deletions lib/water.js
Expand Up @@ -1209,10 +1209,13 @@
water.is_failure = function( v ){ return v && v.watered && v.error && v; };

water.is_success = function( v ){
return (v && !v.watered && v )
|| (typeof v !== "undefined" && (v || true) );
return ( v && !v.watered && v )
|| ( typeof v !== "undefined" && ( v || true ) );
};
water.water = function( w ){ return (w && w._water) || void 0; };

water.water = function( w ){ return ( w && w._water ) || void 0; };

water.is_water = function( w ){ return !!( w && w._water ); };

water.fail = function( e ){
return { watered: (water.current || water), error: e || "fail" };
Expand Down
3 changes: 2 additions & 1 deletion lib/whisper.js
Expand Up @@ -219,7 +219,8 @@

var EcmaLikePromise;
if( typeof Promise !== "undefined" ){
EcmaLikePromise = Promise;
// ToDo: actual Ecma promise are constructors, they need a "new"
EcmaLikePromise = function( f ){ return new Promise( f ) };
}else{
EcmaLikePromise = function( f ){
var p = MakeParole();
Expand Down
17 changes: 9 additions & 8 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "l8",
"version": "0.3.4",
"description": "l8 is an experimental pthread/erlang inspired task manager for javascript. Simple tasks becomes 'paroles', complex tasks become functions broken in 'steps'. l8 comes with synchronisation and distribution tools including semaphores, mutexes, message queues, generators, actors and socket.io proxied actors, among others.",
"version": "0.3.6",
"description": "l8 is an *experimental* pthread/erlang inspired task manager for javascript. Simple tasks becomes 'paroles', complex tasks become functions broken in 'steps'. l8 comes with synchronisation and distribution tools including semaphores, mutexes, message queues, generators, actors and socket.io proxied actors, among others.",
"main": "lib/l8.js",
"files": [
"lib",
Expand All @@ -15,18 +15,19 @@
"node": ">=0.10.0"
},
"dependencies": {
"browserify": "^5.12.1",
"coffee-script": "^1.8.0",
"connect": "^3.2.0",
"matches": "^0.5.1",
"mocha": "^1.21.4",
"mocha-unfunk-reporter": "^0.4.0",
"promises-aplus-tests": "^2.1.0",
"serve-static": "^1.6.3",
"socket.io": "^1.1.0",
"socket.io-client": "^1.1.0"
},
"devDependencies": {},
"devDependencies": {
"browserify": "^8.1.1",
"coffee-script": "^1.8.0",
"mocha": "^1.21.4",
"mocha-unfunk-reporter": "^0.4.0",
"promises-aplus-tests": "^2.1.0"
},
"scripts": {
"postinstall": "ln -s ../. node_modules/l8 || true",
"test": "node test/parole.js && mocha test/boxon.js -R spec && promises-aplus-tests test/promise.js && node test/suite.js && node test/actor.js && node test/node.js"
Expand Down

0 comments on commit 304d455

Please sign in to comment.