timcassell / ProtoPromise

Robust and efficient library for management of asynchronous operations in C#/.Net.
MIT License
180 stars 13 forks source link

Add common Unity awaits to `PromiseYielder` #200

Closed timcassell closed 1 year ago

timcassell commented 1 year ago

Fixes #199 and resolves #196.

Optimized PromiseYielder.WaitOneFrame(). (now 4x faster than yield return null) Deprecated PromiseYielder.WaitOneFrame(MonoBehaviour). (Breaking change, WaitOneFrame() returns a different type now) Added common Unity awaits to PromiseYielder.

timcassell commented 1 year ago

@drew-512 Please take a look. I modeled this after UnityAsync.

You can wait on an AsyncOperation like this (cancelationToken is optional):

PromiseYielder.WaitForAsyncOperation(asyncOp).ToPromise(cancelationToken);

or

await PromiseYielder.WaitForAsyncOperation(asyncOp);

or

await PromiseYielder.WaitForAsyncOperation(asyncOp).WithCancelation(cancelationToken);

or

await PromiseYielder.WaitForAsyncOperation(asyncOp).AwaitWithProgress(0f, 1f, cancelationToken);
drew-512 commented 1 year ago

Love it! Plugging in the latest main today and will be testing it via my Unity AssetBundle wrappers and will report back.

drew-512 commented 1 year ago

Looks like I should use the promiseyielder-updates branch!

drew-512 commented 1 year ago

Looking good so far!

Will put in that latest commit this eve.

timcassell commented 1 year ago

@drew-512 Great! The only change I made in the last push was using Unity's time in WaitForTime instead of scaling a system timer.

drew-512 commented 1 year ago

LGTM

timcassell commented 1 year ago

@drew-512 Tyvm for your feedback!