Skip to content
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

Unexpected results when using runImmediately with job.stop() #176

Open
thenorthernpole opened this issue Apr 17, 2023 · 3 comments
Open

Comments

@thenorthernpole
Copy link

Hi,

I see a logical issue with combining runImmediately with job.stop().
If a job is set to runImmediately, invoking job.stop in its first run will only affect the second run.
So the job will be executed twice, instead of once.

const doMyThing = async (cancellationCallback) => {
     // do something
    cancellationCallback(job)
}

const jobCancellationCallback = (jobToCancel) => {
    jobToCancel.stop()
}

const task = new AsyncTask('Some Fun', () => doMyThing(jobCancellationCallback))
const job = new SimpleIntervalJob(
    { seconds: 2, runImmediately: true},
    task,
    {
        id: 'id_1',
        preventOverrun: true,
    })

Thanks!

@raliqala
Copy link

raliqala commented Jun 2, 2023

If a job is set to runImmediately, invoking job.stop in its first run will only affect the second run.
Hi
Your statement is correct, the job will run the task once then stop it won't run twice because after stop it stopped.

@thenorthernpole
Copy link
Author

Hi, thanks for the reply.
My intention was that it will run twice before stopping.
E.g. the first run will execute the stop but the stop won't work and will thus invoke a second run.
The stop will only prevent the third run.
It only happens with runImmedaitely (as if it invokes an additional task, instead of using the same one)

@kibertoad
Copy link
Owner

Thank you for reporting. I'll look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants