4 ms·
You can use async Tasks as long as you keep them on the main thread. They end up making a lot of garbage though.
by jayd16 4y ago
You can use async Tasks as long as you keep them on the main thread. They end up making a lot of garbage though.
- int_19h 4y agoThat's what ValueTasks are there for, no?
- to11mtm 4y agoIIRC there's a little more work needed for unity, but Cysharp has you covered (https://github.com/Cysharp/UniTask https://github.com/Cysharp/UniTask)
- jayd16 4y agoValueTasks help but they can only be awaited once. The Unity runtime knows how to handles the same IEnumerator yielded by multiple parent routines. Cancellation is another gotcha with Tasks. The main way to cancel tasks is to use exceptions as control flow. This causes cancellation to be very expensive. You can still use cancellation tokens and check for IsCancelled and finish your task cooperatively but then you're kind of doing thinks in an non-canononical way. Unity also hasn't done the work to make cheap unity lifecycle delay calls such as Task wait for end of frame, (although they could). The work arounds are expensive.
- int_19h 4y agoIs that Unity-specific stuff? From my experience, cancellation in idiomatic C# is mostly done via tokens, not exceptions.