Comments (8)
I'm shooting for the "ProtoPromise pure certified" logo seal thing. I hear there's a promo merch gift bag thing.
from protopromise.
There are multiple ways you can do it. You could keep using UnityAsync
and just wrap that await in an async Promise<T>
function. Or you can do it just with Promises:
public static class AssetBundleHelper
{
public static async Promise<T> LoadAssetAsync<T>(AssetBundle bundle, string nameId) where T : Object
{
var request = bundle.LoadAssetAsync<T>(nameId);
await PromiseYielder.WaitFor(request);
return request.asset as T;
}
public static async Promise<T> LoadAssetAsyncWithProgress<T>(AssetBundle bundle, string nameId) where T : Object
{
var request = bundle.LoadAssetAsync<T>(nameId);
while (!request.isDone)
{
await PromiseYielder.WaitOneFrame().AwaitWithProgress(request.progress);
}
return request.asset as T;
}
}
I didn't write any Promise wrappers for Unity-specific async operations, except I wrote a helper to convert any yield instruction (in a coroutine) to a Promise via PromiseYielder.WaitFor
. Since AssetBundleRequest
is a yield instruction, it works for it.
I wanted to show an example for canceling the async operation, but it appears that API does not support aborts. For abortable operations, you can take a look at the Demo for an example.
from protopromise.
I took a look at the UnityAsync
library, and while it looks abandoned, it should work well with ProtoPromise
. They do some optimization tricks that I didn't do in my PromiseYielder
(I pool some objects, but I call StartCoroutine
under the hood, which allocates). I think that should be fine to use until Unity has updated their APIs for async/await goodness (2023).
from protopromise.
Ok great -- and like that you totally checked it out and looked hard at it. Your comments are super helpful thank you.
from protopromise.
I think that should be fine to use until Unity has updated their APIs for async/await goodness (2023).
Have they said that's coming? They seem to be behind on a lot and the internal downsizing can't be helping.
Sad they are not dialing up engineering investment more considering that signs point to in ~5 years the platforms of choice will be Unity and Unreal (or what becomes of Unreal when part of Tangent is sold or otherwise acquired to make it "safe" for U.S. consumption) -- not the native OSes.
I digress, but I do think that makes a ProtoPromise a great candidate for long term success.
Best,
Drew
from protopromise.
I think that should be fine to use until Unity has updated their APIs for async/await goodness (2023).
Have they said that's coming?
It's already done in the pre-release. https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Awaitable.html
Although, it looks like Unity dropped the ball once again... The Awaitable
type is a class, and the static functions like Awaitable.NextFrameAsync()
return Awaitable
, so they probably allocate. It looks like they copied Task
too closely, and then refused to even call it UnityTask
. Ugh.
from protopromise.
Since Unity did such a terrible job of it, I think I'll add more optimized PromiseYielder
functions for common Unity awaits (WaitFrames(int)
, WaitFor(TimeSpan)
, WaitFor(AsyncOperation)
, WaitForFixedUpdate
, WaitForEndOfFrame
, etc). That way you won't have to rely on UnityAsync
for optimal efficiency.
from protopromise.
So strange and sad they are so careless about that stuff.
Psyched you're on the case!
from protopromise.
Related Issues (20)
- Race condition
- Cancelation race condition
- `AsyncReaderWriterLock` Contention Strategy HOT 5
- Use spin lock in async synchronization primitives
- Methods to troubleshoot UnobservedPromiseException HOT 24
- Fatal error when building macOS player HOT 3
- `PromiseYielder.WaitOneFrame().ToPromise()` waits an extra frame.
- Add analyzer to prevent accidental misuse of `AsyncEnumerable`
- Add `Promise.ParallelForEachAsync`
- Add async Linq extensions for `AsyncEnumerable` HOT 1
- Add `AsyncEnumerable.Merge`
- Add `AsyncEnumerable` convenient generators
- Decouple Progress from Promises HOT 1
- Add `Promise.Finally` overloads that accept `Func<Promise>` delegates
- Add overloads that accept `Span<T>` parameter
- Update readme with instructions to install analyzer in Unity
- Add `Channel` type
- Add parallel async Linq
- Add Unity `Awaitable` conversion to `Promise`
- Add Promise groups
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protopromise.