UniTaskPubSub icon indicating copy to clipboard operation
UniTaskPubSub copied to clipboard

CancellationToken in AsyncMessageBus.Subscribe is not used anywhere

Open Razenpok opened this issue 4 years ago • 3 comments

https://github.com/hadashiA/UniTaskPubSub/blob/cde09c607cb29e33e80c8fa04a12afe559455b97/Assets/UniTaskPubSub/Runtime/AsyncMessageBus.cs#L162

Razenpok avatar Mar 01 '21 10:03 Razenpok

Ooh..! That's my mistake.

Currently only the return value IDisposable is being used, and the CancellationToken is not being used at all.

In the case of Subscribe in UniTask.Linq, it seems to either return IDisposable or pass in the CancellationToken and return nothing (void).

I would like to change to this kind of API as well. Thanks for the report

hadashiA avatar Mar 08 '21 02:03 hadashiA

Tbh I can see how both IDisposable and CancellationToken can be used here:

  • IDisposable could cancel new invocations (current implementation)
  • CancellationToken could be linked with the token passed via Publish to cancel current subscriptions

Like this (I'm using UniRx for Add to):

private void Start()
{
    AsyncMessageBus.Subscribe<Message>(Handle, this.GetCancellationTokenOnDestroy()).AddTo(this);
}

Here, when OnDestroy actually happens, both new Handle invocations would be prevented and in-progress invocations would be cancelled.

Razenpok avatar Mar 08 '21 15:03 Razenpok

Tbh I can see how both IDisposable and CancellationToken can be used here:

I think it is possible, as you said.

However, it seems to me that it is not obvious what effect each of Disposable and CancellationToken will have when used together.

Also, it seems to me that using one or the other would be sufficient in the general case.

Let me think about this.

hadashiA avatar Mar 12 '21 02:03 hadashiA