Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update promises to be awaitable using async/await #216

Open
matronator opened this issue May 14, 2022 · 6 comments
Open

Update promises to be awaitable using async/await #216

matronator opened this issue May 14, 2022 · 6 comments

Comments

@matronator
Copy link

Promises are so ugly, especially when you have to chain multiple .Then() blocks. So I tried to await the promise instead, but it won't compile because they're not awaitable.

Now this might be just a misunderstanding of C# promises, coming from JavaScript ESNext, but isn't async/await basically the same thing as promises, but with much cleaner and nicer syntax?

As in, doesn't this code

RestClient.Get("/api/something")
.Then(response => {
    Debug.Log(response.Text);
});

do the exact same thing as this one?

var response = await RestClient.Get("/api/something");
Debug.Log(response.Text);

Or at least it would if the promise could be awaited. Which would be awesome!

@jdnichollsc
Copy link
Member

Hello dude, thanks for reporting this issue

This plugin supports multiple versions of Unity, since .NET Framework 3.5 and async/await syntax is not supported in previous versions, that's why we are using RSG.Promise for management of async operations, any ideas or pull requests to support async/await are really welcome! ❤️

@timcassell
Copy link

Shameless plug - probably a non-starter, but I built a Promise library that supports async/await, is much more efficient than RSG (on par with UniTask), and supports old versions of Unity also. I say non-starter because switching from RSG to Proto.Promises would likely break consumers of this library, but maybe worth taking a look (maybe for a v3 update?). 😄

https://github.com/timcassell/ProtoPromise

@jdnichollsc
Copy link
Member

@timcassell congrats mate, that's amazing! 💯

@timcassell
Copy link

timcassell commented Aug 8, 2022

@jdnichollsc Does that mean you're interested in making the switch? I'd be happy to help with the integration if you want.

As a bonus, the Promise source code wouldn't need to be included in the package like you did with RSG, since ProtoPromise is on the asset store and nuget, so it could just be listed as a dependency instead.

@jdnichollsc
Copy link
Member

@timcassell sure thing, any pull request is really appreciated, thanks in advance for your contribution! ❤️

@timcassell
Copy link

timcassell commented Sep 1, 2022

@jdnichollsc Cool. Before I start, I want to understand how the nuget package works. Are you including the Unity dlls in the package? How is the nuget package consumed? Does it work outside of Unity? What differences are there between the nuget package and unity package?

[Edit] I ask because I have some Unity-specific helpers in ProtoPromise that are not included in the nuget package, only in the unity package, so that it can work on other frameworks. I may have to package those helpers as a separate nuget package, depending how your nuget package works.

[Edit2] I went ahead and made that separate package anyway, and updated the core package to work in old Unity versions (notably IL2CPP that had a lot of problems that I had to work around prior to Unity 2021.2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants