question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coroutines evolution

See original GitHub issue

Summary

This thread is to continue the discussions going on in the Coroutines’ implementation PR #801, and to avoid cluttering the PR itself.

In particular, it emerged that further down the road, it could be worthy to investigate the following two aspects that are currently not managed, related to the management aspects of the new Coroutines system.

Saving/Loading Coroutines

As it is now, the system does not support saving and loading of Coroutines; it might be possible that during de/serialization the status is preserved “automagically”, were the coroutineManager be serializable in the Scene, but testing is definitely required to be sure of the results of this operation. From a quick glance at Unity’s references, it appears that this topic still doesn’t have an out-of-the-box solution, and relies on the user’s management to determine which variables need to be saved and how to restore the Coroutine to the desired state. https://docs.unity3d.com/Manual/Coroutines.html https://docs.unity3d.com/ScriptReference/Coroutine.html https://answers.unity.com/questions/1433878/how-to-store-the-state-of-ienumertor-and-resume-th.html https://forum.unity.com/threads/how-can-i-save-and-load-a-coroutine-state.796401/

Automatically clearing up Coroutines when the spawning GameObject gets removed

Currently the system doesn’t track, and is not interested in, the context in which a Coroutine has been spawned; the Coroutine has the capability to affect any number of Entities in any Scene, and its execution is anyway managed so that an error would not result in an unrecoverable state of the engine.

A possible solution, as proposed by @Barsonax, would be to assign to each GameObject (and/or Component) a list of Coroutines that would be automatically Cancelled once their respective “container” is being removed from the Scene. (Bonus: they could be paused/resumed automatically on de/activation). This would be an extra facility, in addition to the current way to start Coroutines.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Barsonaxcommented, May 18, 2020

Another thing we might want to look into in the future: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=dotnet-plat-ext-3.1

Basically the combination of a itterator and async

1reaction
Barsonaxcommented, May 12, 2020

A possible solution, as proposed by @Barsonax, would be to assign to each GameObject (and/or Component) a list of Coroutines that would be automatically Cancelled once their respective “container” is being removed from the Scene. (Bonus: they could be paused/resumed automatically on de/activation). This would be an extra facility, in addition to the current way to start Coroutines.

I think we should do this on component level and generalize it so it will work for more than just coroutines. In the future we might also have a job system which makes use of this and the enduser might also want to use this API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The rise of the coroutines
Most notably, Python started adding coroutines as a mechanism for writing concurrent code in 2005 and evolved this approach over the years.
Read more >
40 Years Of Evolution from Functions to Coroutines - YouTube
https://cppcon.org/ https://github.com/CppCon/CppCon2020 --- The evolution of a callable stands for the evolution of C++.
Read more >
The evolution of coroutine in Python.
From the beginning generator to the final native coroutine, the fundamental changes a little. With an frame object, the execution process is devided...
Read more >
Coroutine
Coroutines are computer program components that allow execution to be suspended and resumed, generalizing subroutines for cooperative multitasking.
Read more >
How to make sense of Kotlin coroutines | by Joffrey Bion
Coroutines are a great way to write asynchronous code that is perfectly readable and maintainable. Kotlin provides the building block of asynchronous ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found