Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ozer550 committed Mar 5, 2025
1 parent 2330eed commit 38d341c
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions packages/kolibri-common/composables/useTaskPooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ import { useTimeoutPoll } from '@vueuse/core';

const taskPollers = new Map();

export function useTaskPooling(queueName, fetchTaskFunction, interval = 5000){
if(!taskPollers.has(queueName)){
export function useTaskPooling(queueName, fetchTaskFunction, interval = 5000) {
if (!taskPollers.has(queueName)) {
const consumers = ref(0);
const tasks = ref([]);

const {pause, resume, isActive} = useTimeoutPoll(async () => {
try{
tasks.value = await fetchTaskFunction();
}
catch(e){
console.error(e);
}
}, interval, { immediate: true });
const { pause, resume, isActive } = useTimeoutPoll(
async () => {
try {
tasks.value = await fetchTaskFunction();
} catch (e) {
console.error(e);
}
},
interval,
{ immediate: true },
);

//TO DECIDE if the key should be uniquely
// identified by the queueName,
// queueName + fetchTaskFunction or queueName + fetchTaskFunction + interval
taskPollers.set(queueName, { consumers, tasks, pause, resume, isActive });

}

const poller = taskPollers.get(queueName);
Expand All @@ -41,11 +43,5 @@ export function useTaskPooling(queueName, fetchTaskFunction, interval = 5000){
}
});

return { tasks: poller.tasks };

return { tasks: poller.tasks };
}





0 comments on commit 38d341c

Please sign in to comment.