Cysharp / R3

The new future of dotnet/reactive and UniRx.
MIT License
1.71k stars 70 forks source link

ChunkFrame() and custom FrameProvider #202

Closed Maligan closed 1 month ago

Maligan commented 1 month ago

Hello!

I have CustomFrameProvider (which has special context before run) and subscription like this:

Observable
    .EveryUpdate(CustomFrameProvider.PostUpdate)
    .ChunkFrame(10)
    .Subscribe(_ => DoUpdate())
    .AddTo(this);

But the problem is that DoUpdate() calls not during my CustomFrameProvider.PostUpdate run but in the ObservableSystem.DefaultFrameProvider one and I don't have the context which I setup before my provider run.

Passing my provider as param into ChunkFrame() or adding of ObserveOn(CustomFrameProvider.PostUpdate) after chunk solves my problem but for me it looks like unobvious behavior.

Just wanted to highlight this case, and don't sure is it by-design or not!

Best Regards!

neuecc commented 1 month ago

Oh, that's a great point! Regarding Count, it seems correct to have it operate in an immediate manner (which should also reduce overhead), so I will make that change!

neuecc commented 1 month ago

Ah, I apologize for the slight misunderstanding. You are correct that a specific FrameProvider is necessary to count frames anyway. So, the current specification is correct, and in that case, using ChunkFrame(count, FrameProvider) is preferable to using ObserveOn. In your situation, where it is certain that the process will reach the frame-based PostUpdate on EveryUpdate, using Chunk(count) would be a good choice.