mirror of https://github.com/Cysharp/UniTask
Suppress allocations around UniTask<T>.AsUniTask and UniTask.AsAsyncUnitUniTask
- Fix completedTask.AsUniTask or completedTask.AsAsyncUnitUniTask leaks IUniTaskSource - UniTask.AsAsyncUnitUniTask no longer allocates when its inner IUniTaskSource is IUniTaskSource<AsyncUnit>pull/203/head
parent
3115efb672
commit
a455de88b0
|
@ -115,8 +115,13 @@ namespace Cysharp.Threading.Tasks
|
|||
var status = this.source.GetStatus(this.token);
|
||||
if (status.IsCompletedSuccessfully())
|
||||
{
|
||||
this.source.GetResult(this.token);
|
||||
return CompletedTasks.AsyncUnit;
|
||||
}
|
||||
else if(this.source is IUniTaskSource<AsyncUnit> asyncUnitSource)
|
||||
{
|
||||
return new UniTask<AsyncUnit>(asyncUnitSource, this.token);
|
||||
}
|
||||
|
||||
return new UniTask<AsyncUnit>(new AsyncUnitSource(this.source), this.token);
|
||||
}
|
||||
|
@ -422,6 +427,7 @@ namespace Cysharp.Threading.Tasks
|
|||
var status = this.source.GetStatus(this.token);
|
||||
if (status.IsCompletedSuccessfully())
|
||||
{
|
||||
this.source.GetResult(this.token);
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue