Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

decisions cannot be changed during runtime (zalgo?) #1

Description

@thfrei

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()),

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions