I would like to implement a task modifier that, when added to a task, will make it throw an error if it takes too long.
It would be used like this:
myTask = task({timeout: 3000}, async () => {
await someAsyncStuff
})
and if someAsyncStuff doesn't resolve or reject within the specified time it will throw a timeout error
This is what I've tried, but it doesn't seem to work.
import {race, rawTimeout} from 'ember-concurrency';
export default function timeout(taskFactory, time) {
const taskDefinition = taskFactory.taskDefinition;
const timer = async () => {
await rawTimeout(time);
throw new Error(timeout);
};
const timeoutTaskDefinition = function* (...args) {
yield* race([
taskDefinition.call(this, ...args),
timer()
]);
};
taskFactory.setTaskDefinition(timeoutTaskDefinition);
}
// initializer
import {registerModifier} from 'ember-concurrency';
import timeoutTaskModifer from 'frontend/task-modifiers/timeout';
registerModifier('timeout', timeoutTaskModifer);
It throws this error when starting the task
Uncaught TypeError: yield* (intermediate value) is not iterable
Any help would be appreciated.
I would like to implement a task modifier that, when added to a task, will make it throw an error if it takes too long.
It would be used like this:
and if
someAsyncStuffdoesn't resolve or reject within the specified time it will throw atimeouterrorThis is what I've tried, but it doesn't seem to work.
It throws this error when starting the task
Uncaught TypeError: yield* (intermediate value) is not iterableAny help would be appreciated.