UniRx icon indicating copy to clipboard operation
UniRx copied to clipboard

Are there something like ThrottleWhile or SubscribeAsync ?

Open Thaina opened this issue 3 years ago • 0 comments

I have an asynchronous subscribe logic and when it run I don't want it to run again until that logic is finished. But if there is any event observed while the logic is run, it will be throttle until the subscribe logic is finished, and then fire again immediately

So I wish that I could write

observable.SubscribeAsync(async(data) => await DoSomething(data))`

Or more precisely. I want to Throttle the input data, not skipping or waiting but throttling it. So I think it might be better if we have ThrottleWhile (and maybe also DebounceWhile or ThrottleUntil)

bool running = false;
observable.ThrottleWhile((_) => running).Subscribe((data) => {
    try
    {
        running = true;
        await DoSomething(data);
    }
    finally
    {
        running = false;
    }
})`

Is this already possible?

Thaina avatar Aug 07 '20 05:08 Thaina