Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow.rule should provide callback support #94

Closed
bthibault opened this issue Dec 13, 2013 · 4 comments
Closed

flow.rule should provide callback support #94

bthibault opened this issue Dec 13, 2013 · 4 comments

Comments

@bthibault
Copy link

I believe that is the issue here:

 // define the rule
    flow.rule("RULE", criteriaArray,
      function(facts) {
         _self = this;
         // do some fact modification asynchronously 
         ruleAction.run(facts.p, rg.then.params, function(err, results) {
                // alert the engine the rule has been modified
                _self.modify(facts.p); 
                _self.retract(facts.p); 
         });
  });

So whats happening here, is the async function ruleAction.run is run, BUT the rule has already fired, which moves the pointer on the linked list then we try to call _self.modify but the fact has already been unlinked.

So we have an async call, with no way to do a callback.

@bthibault
Copy link
Author

admittedly i'm a node / js n00b so there could be another for me to structure it.

@doug-martin
Copy link
Contributor

Try this

 // define the rule
    flow.rule("RULE", criteriaArray,
      function(facts, engine, next) {
         _self = this;
         // do some fact modification asynchronously 
         ruleAction.run(facts.p, rg.then.params, function(err, results) {
                if(err){
                    next(err);
                }else{
                // alert the engine the rule has been modified
                _self.modify(facts.p); 
                _self.retract(facts.p); 
                next();
               }
         });
  });

@doug-martin
Copy link
Contributor

I should also note if you are using the DSL then you can just use next. See the action section for a detailed explanation. I'll also update the readme to have a section dedicated about asynchronous actions in nools, since this isn't the first time some one has brought this up.

@bthibault
Copy link
Author

hey hey. it worked.

Thanks

doug-martin added a commit to doug-martin/nools that referenced this issue Dec 17, 2013
* Added new `getFacts` method to allow for querying of facts currently in session. noolsjs#52;
* Added indexing on comparison operators (i.e. `>, <, >=, <=`).
* Updated documentation.
   * Added new section about retrieving facts from a session.
   * Created new section for async actions to address noolsjs#94
@doug-martin doug-martin mentioned this issue Dec 17, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants