So I was wandering if this is like a typical synchronous, asynchronous issue.
In order to demonstrate, I modified an existing example.
What I want is, that uppon listening, I set some vaues, in this case a new name, and then send this back in my decision. However it does not work:
var babble = require('../index');
var emma = babble.babbler('emma');
var jack = babble.babbler('jack');
var newName = 'foo';
emma.listen('hi')
.listen(function (message, context) {
console.log(context.from + ': ' + message);
newName = 'baaaaaaaar';
return message;
})
.decide(function (message, context) {
return (message.indexOf('age') != -1) ? 'age' : 'name';
}, {
'name': babble.tell('hi, my name is not emma but:'+newName),
'age': babble.tell('hi, my age is 27')
});
jack.tell('emma', 'hi')
.tell(function (message, context) {
if (Math.random() > 0.5) {
return 'my name is jack'
} else {
return 'my age is 25';
}
})
.listen(function (message, context) {
console.log(context.from + ': ' + message);
});
Console Output:
jack: my name is jack
emma: hi, my name is not emma but:foo
Maybe it is not a big issue, but in my point of view the flow would seem more natural.
PS:
Another symptom is, if you put a function, it will immediatly be executed, regardless of whether this decision is taken or not:
function tellName() {
console.log('foobar');
return 'whatever';
}
....
'name': babble.tell(tellName()),
So I was wandering if this is like a typical synchronous, asynchronous issue.
In order to demonstrate, I modified an existing example.
What I want is, that uppon listening, I set some vaues, in this case a new name, and then send this back in my decision. However it does not work:
Console Output:
Maybe it is not a big issue, but in my point of view the flow would seem more natural.
PS:
Another symptom is, if you put a function, it will immediatly be executed, regardless of whether this decision is taken or not: