|
78 | 78 | }; |
79 | 79 |
|
80 | 80 | /* |
81 | | - * Asynchronous function which makes a get call to the solutions registry (1st parameter) to |
| 81 | + * Asynchronous/Promise returning function which makes a get call to the solutions registry (1st parameter) to |
82 | 82 | * retrieve the solutions registry matching what is passed in the `device` parameter. |
83 | 83 | * This is appended to the matchmaker payload (mmpayload) parameter, which in turn is passed |
84 | 84 | * as parameter in the event fired. |
85 | 85 | * |
| 86 | + * This function can be used with either (or both) asyncronously with an `event` and `onError` handlers |
| 87 | + * passed in, or with the returned `fluid.promise`. |
| 88 | + * |
86 | 89 | * @solutionsRegistryDataSource (Object) - a solutions registry data source |
87 | 90 | * @deviceContext (Object) - output from a device reporter. Used to filter solutions registry entries |
88 | | - * @event (Object) - Event to be fired when the solutionsRegistry entry has been retrieved |
89 | | - * @onError (Object) - Event to be fired when an error occurs |
| 91 | + * @event (Object) - Optional: Event to be fired when the solutionsRegistry entry has been retrieved |
| 92 | + * @onError (Object) - Optional: Event to be fired when an error occurs |
90 | 93 | * |
91 | | - * @return (undefined) - function is asynchronous and doesn't return anything. Instead the event |
92 | | - * is fired with the modified mmpayload. |
| 94 | + * @return (fluid.promise) - Returns a promise resolving with the mmpayload . Optionally if provided, the events |
| 95 | + * are also fired with the modified mmpayload. |
93 | 96 | */ |
94 | 97 | gpii.flowManager.getSolutions = function (solutionsRegistryDataSource, deviceContext, event, onError) { |
95 | | - gpii.flowManager.getSolutionsPromise(solutionsRegistryDataSource, deviceContext).then( |
96 | | - function (data) { |
97 | | - event.fire(data.solutionsRegistryEntries, data.solutions); |
98 | | - }, |
99 | | - onError.fire |
100 | | - ); |
101 | | - }; |
102 | | - |
103 | | - gpii.flowManager.getSolutionsPromise = function (solutionsRegistryDataSource, deviceContext) { |
104 | 98 | var promiseTogo = fluid.promise(); |
105 | 99 |
|
106 | 100 | var os = fluid.get(deviceContext, "OS.id"); |
|
112 | 106 | solutionsRegistryEntries: solutionsRegistryEntries, |
113 | 107 | solutions: solutions |
114 | 108 | }); |
115 | | - }, promiseTogo.reject); |
| 109 | + if (event) { |
| 110 | + event.fire(solutionsRegistryEntries, solutions); |
| 111 | + } |
| 112 | + }, function (error) { |
| 113 | + promiseTogo.reject(error); |
| 114 | + if (onError) { |
| 115 | + onError.fire(error); |
| 116 | + } |
| 117 | + }); |
116 | 118 |
|
117 | 119 | return promiseTogo; |
118 | 120 | }; |
|
0 commit comments