Skip to content

Commit

Permalink
Added Dezalgo to simulate asynchronicity
Browse files Browse the repository at this point in the history
See #414
  • Loading branch information
mcollina committed May 5, 2016
1 parent 86ed42a commit 2eb2a6a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 71 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"archy": "1.0.0",
"delayed-open-queue": "^0.1.0",
"dezalgo": "^1.0.3",
"eraro": "0.4.1",
"gex": "0.2.2",
"jsonic": "0.2.2",
Expand Down
3 changes: 2 additions & 1 deletion seneca.js
Expand Up @@ -19,6 +19,7 @@ var Parambulator = require('parambulator')
var Stats = require('rolling-stats')
var Zig = require('zig')
var DelayedOpenQueue = require('delayed-open-queue')
var Dezalgo = require('dezalgo')

// Internal modules.
var Actions = require('./lib/actions')
Expand Down Expand Up @@ -952,7 +953,7 @@ function make_seneca (initial_options) {

args.default$ = args.default$ || (!so.strict.find ? {} : args.default$)
prior_ctxt = prior_ctxt || { chain: [], entry: true, depth: 1 }
actdone = actdone || _.noop
actdone = actdone && Dezalgo(actdone) || _.noop


// if previously seen message, provide previous result, and don't process again
Expand Down
40 changes: 20 additions & 20 deletions test/error.test.js
Expand Up @@ -47,28 +47,28 @@ describe('seneca-error', function () {
assert.ok(ctxt.errlog === null)
assert.equal(out[0], 1)
assert.ok(out[1], 'foo')
})

// ~~ CASE: callback; no-default; err-result; err-logged
si.act('a:1', function (err, out) {
assert.equal(out, null)
assert.equal('act_not_found', err.code)
// assert.equal('act_not_found', ctxt.errlog[8])

// ~~ CASE: callback; bad-default; err-result; err-logged
si.act('a:1,default$:"foo"', function (err, out) {
// ~~ CASE: callback; no-default; err-result; err-logged
si.act('a:1', function (err, out) {
assert.equal(out, null)
assert.equal('act_default_bad', err.code)
// assert.equal('act_default_bad', ctxt.errlog[8])

// ~~ CASE: fragile; throws; err-logged
si.options({debug: {fragile: true}})
ctxt.errlog = null

si.act('a:1', function (ex) {
assert.equal('act_not_found', ex.code)
// assert.equal('act_not_found', ctxt.errlog[8])
return done()
assert.equal('act_not_found', err.code)
// assert.equal('act_not_found', ctxt.errlog[8])

// ~~ CASE: callback; bad-default; err-result; err-logged
si.act('a:1,default$:"foo"', function (err, out) {
assert.equal(out, null)
assert.equal('act_default_bad', err.code)
// assert.equal('act_default_bad', ctxt.errlog[8])

// ~~ CASE: fragile; throws; err-logged
si.options({debug: {fragile: true}})
ctxt.errlog = null

si.act('a:1', function (ex) {
assert.equal('act_not_found', ex.code)
// assert.equal('act_not_found', ctxt.errlog[8])
return done()
})
})
})
})
Expand Down
98 changes: 48 additions & 50 deletions test/seneca.test.js
Expand Up @@ -428,59 +428,57 @@ describe('seneca', function () {
var count = 0
var called = ''

si.ready(function () {
si.add('foo:a', function (args, done) {
count++
count += args.x
done(null, {count: count})
})
si.add('foo:a', function (args, done) {
count++
count += args.x
done(null, {count: count})
})

si.add('foo:a', function (args, done) {
count += args.y
this.prior(args, done)
si.add('foo:a', function (args, done) {
count += args.y
this.prior(args, done)
})

si
.act('foo:a,x:10,y:0.1', function (err, out) {
assert.equal(err, null)
assert.equal(11.1, count)
called += 'A'
})
.act('foo:a,x:100,y:0.01', function (err, out) {
assert.equal(err, null)
assert.equal(112.11, count)
called += 'B'
})
.act('foo:a,x:10,y:0.1', function (err, out) {
assert.equal(err, null)
assert.equal(123.21, count)
called += 'C'
})
.act('foo:a,x:100,y:0.01', function (err, out) {
assert.equal(err, null)
assert.equal(224.22, count)
called += 'D'
})
.ready(function () {
assert.equal('ABCD', called)
assert.equal(224.22, count)

si
.act('foo:a,x:10,y:0.1', function (err, out) {
assert.equal(err, null)
assert.equal(11.1, count)
called += 'A'
})
.act('foo:a,x:100,y:0.01', function (err, out) {
assert.equal(err, null)
assert.equal(112.11, count)
called += 'B'
})
.act('foo:a,x:10,y:0.1', function (err, out) {
assert.equal(err, null)
assert.equal(123.21, count)
called += 'C'
})
.act('foo:a,x:100,y:0.01', function (err, out) {
assert.equal(err, null)
assert.equal(224.22, count)
called += 'D'
})
.ready(function () {
assert.equal('ABCD', called)
assert.equal(224.22, count)

this
.add('foo:a', function (args, done) {
count += args.z
this.prior(args, done)
})
.act('foo:a,x:10,y:0.1,z:1000000', function (err, out) {
assert.equal(err, null)
assert.equal(1000235.32, count)
called += 'E'
})
.ready(function () {
assert.equal('ABCDE', called)
done()
})
})
})
this
.add('foo:a', function (args, done) {
count += args.z
this.prior(args, done)
})
.act('foo:a,x:10,y:0.1,z:1000000', function (err, out) {
assert.equal(err, null)
assert.equal(1000235.32, count)
called += 'E'
})
.ready(function () {
assert.equal('ABCDE', called)
done()
})
})
})

it('gating', function (done) {
Expand Down

0 comments on commit 2eb2a6a

Please sign in to comment.