Closed Lionad-Morotar closed 4 months ago
Hey!
You can create a wrapper like this:
type Generator = Parameters<typeof useTask>[0];
export function useDropTask(cb: Generator) {
return useTask(cb).drop();
}
I'd calll it useDropTask
but since you likely want to save typing you could call it useTask
and import the original as something else:
import { useTask as useTaskOriginal } from 'vue-concurrency';
type Generator = Parameters<typeof useTaskOriginal>[0];
export function useTask(cb: Generator) {
return useTaskOriginal(cb).drop();
}
But the big issue here is that useTask().restartable()
will not turn off the drop()
so you'll end up with both which does not make that much sense.
So at the end of the day you could go for this setting:
import { useTask as useTaskOriginal } from 'vue-concurrency';
type Generator = Parameters<typeof useTaskOriginal>[0];
export function useTask(cb: Generator, concurrency: 'drop' | 'restartable' | 'keepLatest' | null = 'drop') {
const task = useTaskOriginal(cb);
if (concurrency) {
task[concurrency]();
}
}
const myTask = useTask(function*(){
//...
}); // drop
const myOtherTask = useTask(function*() {
// ...
}, 'restartable').
const myOtherTask = useTask(function*() {
// ...
}, null). // this one allows parallel runs
I'm not sure if any of these are ideal :D There could totally be global config as that could also solve https://github.com/MartinMalinda/vue-concurrency/issues/50 but so far it's missing.
Thank you! My problem is solved now.
glad to see if theres a global config in new version
Hello,how can I use
drop
as default concurrency policy? so that I can ignore.drop()
on eachuseTask
call.Also,thanks for this great tool