UNPKG

1.33 kBJavaScriptView Raw
1import isFunction from "lodash-es/isFunction"
2import MeasurementFramework from "./MeasurementFramework"
3import forEach from "lodash-es/forEach"
4
5let customTaskFunctions = []
6
7export default function customTask(func) {
8 if (isFunction(func)) {
9 customTaskFunctions.push(func)
10 MeasurementFramework.register(function () {
11 return {
12 'customTaskRunner': function () {
13 return function (customTaskModel) {
14 forEach(customTaskFunctions, function (taskFunction) {
15 try {
16 /**
17 * Wrapping this in a try/catch as its madly critical.
18 */
19 taskFunction(customTaskModel)
20 } catch (e) {
21 console.error("customTaskRunner error: ", e.message)
22 }
23 })
24 /**
25 * Taskrunner returns a common status.
26 */
27 }
28 },
29 'customTasksRegistered': customTaskFunctions.length
30 }
31 })
32 } else {
33 console.warn("Measurement Framework received a non-function.", func)
34 }
35
36}
\No newline at end of file