CancellationToken in AsyncMessageBus.Subscribe is not used anywhere
https://github.com/hadashiA/UniTaskPubSub/blob/cde09c607cb29e33e80c8fa04a12afe559455b97/Assets/UniTaskPubSub/Runtime/AsyncMessageBus.cs#L162
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
Tbh I can see how both IDisposable and CancellationToken can be used here:
IDisposablecould cancel new invocations (current implementation)CancellationTokencould be linked with the token passed viaPublishto 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.
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.