sledorze/monax — Issue #2: nodejs monad is called two time with haxe timer delay
Author: francescoagati
Created: 2012-01-24 09:39:32+00:00
State: open

Hi,
i have try to modify the nodejs monad in test example for simulate async function with haxe timer delay. It work fine but the function with the trace is calling two times.

Here the code. I've tested the compiled js on safari browser

```
import com.mindrocks.monads.instances.Prelude;

import com.mindrocks.monads.Monad;
import com.mindrocks.monads.instances.NodeJs;

using com.mindrocks.monads.instances.Prelude;

class Obj {
var name : String;
public function new(name : String) {
this.name = name;
}
}

class Collection {
var objs : Array;
public function new() {
objs = [new Obj("a"), new Obj("b")];
}
public function all(name : Dynamic, cb : Error -> Array -> Void) {
// cb("Aieeeuu!!", null);
haxe.Timer.delay(function() {
cb(null, objs);
}, 1000);

}
}

class DB {
var coll : Collection;
public function new() {
coll = new Collection();
}
public function collection(name : String, cb : Error -> Collection -> Void) {

haxe.Timer.delay(function() {
cb(null, coll);
}, 1000);

}
}

class Main {

public static function main(){

var db = new DB();
var res5 : String = "";

NodeM.dO({
coll <= db.collection("avatars", _);
avatars <= coll.all("ssss", _);
ret(avatars.length);
})(function (err, res) trace(res));

}

}

```