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

Extend Scheduler#scheduleDirect with a Disposable container #7445

Closed
sahil2441 opened this issue Jul 1, 2022 · 1 comment
Closed

Extend Scheduler#scheduleDirect with a Disposable container #7445

sahil2441 opened this issue Jul 1, 2022 · 1 comment

Comments

@sahil2441
Copy link

There's recent API addition in 3.1.0 that adds a composite in the subscribe() calls as a 4th parameter so that when the upstream terminates the disposable is also disposed.

In our application we use Scheduler#scheduleDirect very often.
It'd be nice to extend Scheduler#scheduleDirect with a Composite so that returned the Disposable is automatically disposed when the upstream terminates.

@akarnokd
Copy link
Member

akarnokd commented Jul 1, 2022

You mean when the scheduled task completes?

We don't want to expand the Scheduler API into that direction so I suggest an utility method for you instead:

public static Disposable schedule(Scheduler scheduler, Runnable run, 
        DisposableContainer container) {
    SerialDisposable d = new SerialDisposable();
    container.add(d);
    d.replace(scheduler.scheduleDirect(() -> {
        try {
             run.run();
        } finally {
             container.delete(d);
        }
    }));
    return Disposable.fromRunnable(() -> container.remove(d));
}

@akarnokd akarnokd closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants