-
Notifications
You must be signed in to change notification settings - Fork 149
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
Instance of Promise is not awaitable #76
Comments
Why don't you just use a Task? |
In order to be an awaiter an object must implement the Unity is gradually upgrading to support .NET Standard 2.0 and .NET Framwork 4.6, but only .NET Framework 3.5 is considered "stable" in the current Unity LTS release (2017.4), which will still be supported until 2020. Although Unity 2018.1 supports the new .NET framework, the older version is still the default. This could be a useful feature but would need to be implemented in a way that still supports the older .NET versions. |
I just made an extension method called .Await() for IPromise that uses TaskCompletionSource. It can't be used in the framework officially because TaskCompletionSource is .NET Framework 4+... But, hopefully this helps you @lm902 Here:
And the extension methods:
|
That's a good idea. I didn't consider using extension methods for this. Once #26 is merged we may be able to use this approach to add the functionality to the main library if there's a clean way to include/exclude these classes depending on the .NET version. |
For older .net versions, Microsoft.Bcl.Async might be an option. |
I've added support for .NET Standard 2.0 in addition to .NET Framework 3.5 so it should be possible to add this now, as long as it's conditionally disabled so it doesn't break the .NET 3.5 build. |
@MorganMoon hey mate, are you using this library with |
I am using this library in a Unity project, and there are some cases where I use it with async/await, however it is not often. I also use the extension methods below as a way to use a Task as a IPromise
|
@MorganMoon awesome Morgan! Do you like to create a Pull Request of your changes to have them from the library? |
@RoryDungan hello mate, one little question And guys, What do you think about this https://github.com/Cysharp/UniTask? |
Yeah conditional compliation would be a good solution if there's an easy way to set that up. I'd rather not add a dependency on UniTask though because some people do use this library in plain C#/.NET projects outside of Unity, so if there's a way to get that functionality without pulling in the whole other library as a dependency that would be ideal. |
Is that still the case? I believe the default LTS version of Unity is now 2019.4, which no longer has .NET Framework 3.5. Only 4.5+ and Standard 2.0. I'm not perfectly sure if this is the right place but I ran into a peculiar situation that may be solved by promises being awaitable: I have a Promise that gets resolved from another thread, which breaks accessing Unity's methods (because the calls no longer come from the main thread). I have a (hacky) workaround by using Promise instead of IPromise, and then looping while CurState is Pending). Something like:
My thinking was that having Promise awaitable would let me do something like:
Would that be possible? Or am I misunderstanding what awaitable Promises are? |
Make promise object awaitable for consistency with ES2017 standard
The text was updated successfully, but these errors were encountered: