@@ -11,7 +11,7 @@ The Engine stores and executes rules, emits events, and maintains state.
11
11
* [ engine.removeRule(Rule instance)] ( #engineremoverulerule-instance )
12
12
* [ engine.addOperator(String operatorName, Function evaluateFunc(factValue, jsonValue))] ( #engineaddoperatorstring-operatorname-function-evaluatefuncfactvalue-jsonvalue )
13
13
* [ engine.removeOperator(String operatorName)] ( #engineremoveoperatorstring-operatorname )
14
- * [ engine.run([ Object facts] , [ Object options] ) -> ; Promise ({ events: Events, almanac: Almanac})] ( #enginerunobject-facts-object-options---promise--events-events-almanac-almanac )
14
+ * [ engine.run([ Object facts] , [ Object options] ) -> ; Promise ({ events: Events, almanac: Almanac, successResults: [ ] , failureResults: [ ] })] ( #enginerunobject-facts-object-options---promise--events-events-almanac-almanac-successresults--failureresults- )
15
15
* [ engine.stop() -> ; Engine] ( #enginestop---engine )
16
16
* [ engine.on('success', Function(Object event, Almanac almanac, RuleResult ruleResult))] ( #engineonsuccess-functionobject-event-almanac-almanac-ruleresult-ruleresult )
17
17
* [ engine.on('failure', Function(Object event, Almanac almanac, RuleResult ruleResult))] ( #engineonfailure-functionobject-event-almanac-almanac-ruleresult-ruleresult )
@@ -156,24 +156,25 @@ engine.removeOperator('startsWithLetter');
156
156
157
157
158
158
159
- ### engine.run([ Object facts] , [ Object options] ) -> Promise ({ events: Events, almanac: Almanac})
159
+ ### engine.run([ Object facts] , [ Object options] ) -> Promise ({ events: Events, almanac: Almanac, successResults: [ ] , failureResults: [ ] })
160
160
161
161
Runs the rules engine. Returns a promise which resolves when all rules have been run.
162
162
163
163
``` js
164
164
// run the engine
165
- engine .run ()
165
+ await engine .run ()
166
166
167
167
// with constant facts
168
- engine .run ({ userId: 1 })
169
-
170
- // returns rule events that were triggered
171
- engine
172
- .run ({ userId: 1 })
173
- .then (function (results ) {
174
- console .log (results .events )
175
- // almanac available via results.almanac to interact with as defined in Almanac docs
176
- })
168
+ await engine .run ({ userId: 1 })
169
+
170
+ // results
171
+ const runResult = await engine .run ({ userId: 1 })
172
+
173
+ /**
174
+ * runResult.almanac: Almanac instance for the run
175
+ * runResult.successEvents: rule results for successful rules
176
+ * runResult.failureEvents: rule results for failed rules
177
+ */
177
178
```
178
179
Link to the [ Almanac documentation] ( ./almanac.md )
179
180
0 commit comments