Last active
October 10, 2020 11:31
-
-
Save shiena/5abbd0930d17159d1d27042f3bffb2c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Foo(Action<int> callback) | |
{ | |
} | |
#region UniTask wrapper | |
private CancellationTokenSource _source; | |
public async void FooAsync() | |
{ | |
using(_source = new CancellationTokenSource()) | |
{ | |
try | |
{ | |
var source = new UniTaskCompletionSource<int>(); | |
using (_source.Token.Register(() => source.TrySetCanceled())) | |
{ | |
Foo(x => source.TrySetResult(x)); | |
var result = await source.Task; | |
Debug.Log(result); | |
} | |
} | |
catch (OperationCanceledException e) | |
{ | |
Debug.LogException(e); | |
} | |
} | |
} | |
public void Cancel() | |
{ | |
_source.Cancel(); | |
} | |
#endregion | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment