Dotween: Suggestion : moving to Task / Await

Created on 26 Jul 2017  路  8Comments  路  Source: Demigiant/dotween

Nothing urgent here, but now that Unity upgraded our C# version and gave us a way to use Async/await nicely with the main thread, it could be cool to move away from callbacks and toward Tasks ?

<3

enhancement resolved

Most helpful comment

Ah, about onComplete, I made them public since a while but didn't push it as a release. There you go :)

All 8 comments

Helloooww :)

Do you mean to replace the various OnComplete/OnEtc callbacks? I still didn't get into the upgraded C# version I have to admit (because I consider it too soon, and ridden with bugs in builds), but what would be the advantages of Tasks vs delegates? Tell me more :)

<3

I'm just starting to dig into this myself, we just upgraded Unity.

First, in term of syntax it should be way cleaner. Instead of having

FirstMethod(SecondMethod(LastMethod))

to chain callbacks, you would have:

await FirstMethod();
await SecondMethod();
await LastMethod();

I need to check all this, I'm more familiar with the javascript implementations of Promises (Tasks/Futures in C# ?) and Async/await. But in general it always make to code cleaner and easier to maintain.

It's a lot of work though, and it may be interesting to see how the guys at Unity are going on their end on this subject. I know they put in place everything needed with Await to plug back into the main thread, so I suppose they are moving away from callbacks too.

<3

I'm not sure that would be useful in this case. Direct callbacks/delegates seems to me they're still the best way to call a single method when an event happens in an engine like DOTween (or to subscribe more methods to the same event).

Chaining multiple methods in a sequence ("sequence" as a logical term, not as DOTween's "Sequence" :P) could eventually be an extra feature, not a replacement for the current system.

But do tell me more when you check into this, because I might just be confused :D

I've been working with Async/Await for a while and it's definitely possible to do some wrappers for DoTween, like

public static async Task<T> IsComplete<T>(this T t) where T : Tween {
    var completionSource = new TaskCompletionSource<T>();
    t.OnComplete(() => completionSource.SetResult(t));
    return await completionSource.Task;
}

The problem here is that I'm overriding the OnComplete of the tween, I can't just append it (onComplete is internal). I'm wondering if I should leave a public getter for onComplete ?

(Btw, I'm thinking of plugging UniRx on top of DOTween, could be a could combo ! )

Ah, about onComplete, I made them public since a while but didn't push it as a release. There you go :)

Awesome, thanks, I can remove my ugly Reflection :D

For future reference I just added async/await support (see this issue) :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wilczarzgit picture wilczarzgit  路  9Comments

kruncher picture kruncher  路  7Comments

Dentrax picture Dentrax  路  10Comments

leeprobert picture leeprobert  路  5Comments

Mukarillo picture Mukarillo  路  4Comments