📄 jobRunner¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| ⚡ Async/Await Patterns | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/core/useWebWorkerFn/lib/jobRunner.ts
Async/Await Patterns¶
| Type | Function | Await Expressions | Promise Chains |
|---|---|---|---|
| promise-chain | jobRunner |
none | Promise.resolve(userFunc.apply(undefined, userFuncArgs)) .then((result) => { ... |
Functions¶
jobRunner(userFunc: Function): (e: MessageEvent) => Promise<void>¶
This function accepts as a parameter a function "userFunc" And as a result returns an anonymous function. This anonymous function, accepts as arguments, the parameters to pass to the function "useArgs" and returns a Promise This function can be used as a wrapper, only inside a Worker because it depends by "postMessage".
Parameters:
userFuncFunction: fn the function to run with web worker
Returns: undefined
returns a function that accepts the parameters
to be passed to the "userFunc" function
Raw JSDoc
/**
* This function accepts as a parameter a function "userFunc"
* And as a result returns an anonymous function.
* This anonymous function, accepts as arguments,
* the parameters to pass to the function "useArgs" and returns a Promise
* This function can be used as a wrapper, only inside a Worker
* because it depends by "postMessage".
*
* @param userFunc {Function} fn the function to run with web worker
*
* @returns returns a function that accepts the parameters
* to be passed to the "userFunc" function
*/
Calls:
Promise.resolve(userFunc.apply(undefined, userFuncArgs)) .then((result) => { postMessage(['SUCCESS', result]) }) .catchpostMessage
Internal Comments:
Code
function jobRunner(userFunc: Function) {
return (e: MessageEvent) => {
const userFuncArgs = e.data[0]
// eslint-disable-next-line prefer-spread
return Promise.resolve(userFunc.apply(undefined, userFuncArgs))
.then((result) => {
postMessage(['SUCCESS', result])
})
.catch((error) => {
postMessage(['ERROR', error])
})
}
}
Generated by Syntax Scribe