Skip to content

Commit e11ce9c

Browse files
authored
Merge pull request #2 from TORISOUP/main
Add CancellationToken to AsyncObjectPool
2 parents 1f57d5e + d97672c commit e11ce9c

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Assets/uPools/Runtime/External/UniTask/AsyncObjectPool.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,30 @@ public AsyncObjectPool(Func<UniTask<T>> createFunc, Action<T> onRent = null, Act
1212
{
1313
if (createFunc == null) throw new ArgumentException(nameof(createFunc));
1414

15+
this.createFunc = _ => createFunc();
16+
this.onRent = onRent;
17+
this.onReturn = onReturn;
18+
this.onDestroy = onDestroy;
19+
}
20+
21+
public AsyncObjectPool(Func<CancellationToken, UniTask<T>> createFunc, Action<T> onRent = null, Action<T> onReturn = null, Action<T> onDestroy = null)
22+
{
23+
if (createFunc == null) throw new ArgumentException(nameof(createFunc));
24+
1525
this.createFunc = createFunc;
1626
this.onRent = onRent;
1727
this.onReturn = onReturn;
1828
this.onDestroy = onDestroy;
1929
}
2030

21-
readonly Func<UniTask<T>> createFunc;
31+
readonly Func<CancellationToken, UniTask<T>> createFunc;
2232
readonly Action<T> onRent;
2333
readonly Action<T> onReturn;
2434
readonly Action<T> onDestroy;
2535

2636
protected override UniTask<T> CreateInstanceAsync(CancellationToken cancellationToken)
2737
{
28-
return createFunc();
38+
return createFunc(cancellationToken);
2939
}
3040

3141
protected override void OnDestroy(T instance)

0 commit comments

Comments
 (0)