Skip to content

Commit

Permalink
direct-directive
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Nov 9, 2023
1 parent ff8ac0e commit 7ad91f0
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 66 deletions.
15 changes: 10 additions & 5 deletions lib/act.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/act.js.map

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions lib/act.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ exports.api_act = function() {
const opts = instance.options()

const spec =
// build_message(instance, [...arguments], 'reply:f?', instance.fixedargs)
ActArgu(arguments)

spec.msg = Object.assign(
Expand Down Expand Up @@ -71,6 +70,7 @@ exports.api_act = function() {
const intern = (module.exports.intern = {
do_act: function(instance: any, opts: any, origmsg: any, origreply: any) {
let timedout = false
let direct = true === origmsg.direct$
const actmsg = intern.make_actmsg(origmsg)
const meta = new Meta(instance, opts, origmsg, origreply)

Expand Down Expand Up @@ -120,7 +120,7 @@ const intern = (module.exports.intern = {
)
} catch (e: any) {

// TODO: review, needs better test for when this actually happens
// TODO: remove
for (let intercept of instance.private$.intercept.act_error) {
intercept.call(instance, {
error: e,
Expand Down Expand Up @@ -163,7 +163,13 @@ const intern = (module.exports.intern = {

execspec.tm = meta.timeout

instance.private$.ge.add(execspec)
if (direct) {
execspec.ctxt = {}
execspec.fn(function complete() { })
}
else {
instance.private$.ge.add(execspec)
}
},


Expand Down
1 change: 0 additions & 1 deletion lib/common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/common.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ function makedie(instance: any, ctxt: any) {
try {
if (!err) {
err = new Error('unknown')
// } else if (!Util.isError(err)) {
} else if (!so.error.identify(err)) {
err = new Error('string' === typeof err ? err : inspect(err))
}
Expand Down
3 changes: 0 additions & 3 deletions seneca.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seneca.js.map

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions seneca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const { Gubu, One, Any, Skip, Open } = require('gubu')
const Eraro = require('eraro')


// Deprecated Legacy modules.
// const Optioner = require('optioner')
// const Joi = require('@hapi/joi')


// Internal modules.
const Common = require('./lib/common')
Expand Down
21 changes: 21 additions & 0 deletions test/act.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,25 @@ describe('act', function () {
})
})
})


it('direct', async () => {
let si = await Seneca({legacy:true}).test().ready()
let log = []

si.add('a:1', function a1(msg, reply) {
log.push('msg-exec')
reply({x:msg.x+1})
})

log.push('pre-msg')
si.act('a:1,x:1,direct$:true', function (err, out) {
expect(err).null()
log.push('reply:'+JSON.stringify(out))
})
log.push('post-msg')

// console.log('log', log)
expect(log).equal(['pre-msg', 'msg-exec', 'reply:{"x":2}', 'post-msg' ])
})
})
51 changes: 5 additions & 46 deletions test/quick.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,20 @@
// const Jsonic = require('@jsonic/jsonic-next')

// Jsonic('a::')

const Seneca = require('../seneca')

// console.log(Seneca.util.Gex('a*'))

let s0 = Seneca({
legacy: false,
// error: {
// capture: {
// callback: false,
// action: false,
// },
// },
system: { action: { add: false } },
})
.test()
// .use('entity')
// .use(function interceptor() {
// let seneca = this
// this.private$.intercept.act_error.push(function foo_interceptor(actcall) {
// console.log('FOO_INTERCEPTOR', actcall)
// })

// })

// .act('sys:entity,hook:intercept,intercept:act_error', {
// action: function foo_interceptor(actcall) {
// console.log('FOO_INTERCEPTOR', actcall)
// }
// }, Seneca.util.print)
.add({ a: 1 }, function a1(msg, reply) {
reply({ x: msg.x })
})
// .add('b:1', function a1(msg, reply) {
// throw new Error('CC')
// })
// .add('role:entity,cmd:list,name:foo', function () {
// throw new Error('DD')
// })
// .listen()
.ready(function () {
// console.log(this.util.Gex('*'))

// this.act('b:1,x:2', function(err, out) {
// console.log(out)
// })

this.act('a:1,x:2', function (err, out) {
console.log(out)
// throw new Error('AA')
console.log('AAA')

this.act('a:1,x:2', {direct$:true}, function (err, out) {
console.log('OUT',out)
})

// this.entity('foo').save$(function(err, out) {
// throw new Error('BB')
// })

// this.entity('foo').list$(Seneca.util.print)
console.log('BBB')
})

0 comments on commit 7ad91f0

Please sign in to comment.