-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BackgroundService.start create multiple task #170
Comments
Hi.. I'm face the same issue, is there any way to solve this problem ? |
Duplicate |
I made a crunch to solve the problem without touching the native part. //this variable is persistent until the app is reloaded with service off
//so we check in a task if the fn argument is the same as 'iteration'
//if it is not we should stop backgroundTask
export let iteration = 0;
export const startBackgroundService = (isThereActiveShift: boolean) => {
if (!BackgroundService.isRunning()) {
iteration++;
BackgroundService.start(backgroundTask.bind(null, iteration), taskOptions)
}
};
export const backgroundTask = async (index: number, taskDataArguments: { delay: number }) => {
await new Promise<void>(async (resolve) => {
for (let i = 0; BackgroundService.isRunning(); i++) {
console.log({ index, iteration });
if (index !== iteration) return;
//your logic here
}
});
}; Ofcourse it's not an ideal solution but it works. |
But know I think the problem of multiple task running simuntenously is solved and my code was this
}, []); function handleOpenURL(evt) { |
Hi. Encounter the problem. I tried adding a delay function after the stop call. |
When I kill my application and open it again and run BackgroundService.start it creates 2 tasks, even running BackgroundService.stop
The text was updated successfully, but these errors were encountered: