C
C#2y ago
rick_o_max

❔ Best strategy to move methods to IEnumerator

Hi guys! I appreciate the help you have been giving on this server. You guys rock! I'm trying to tackle down an architecture issue this time. I have a big codebase (approx. 100k lines of code) which contains processing-intensive methods that might halt the main thread (I'm using Unity). The issue is not Unity specific, as it is a feature from the .NET Framework. On Unity, one can spread large processing across various frames on the main thread by using Couroutines (https://docs.unity3d.com/Manual/Coroutines.html). Inside a Coroutine, the code can suspend it until the yield instruction is accepted. I'm looking for ways to convert my codebase to IEnumerator, so I can make use of Coroutines, but I think putting lots of conditional compilation stuff like #ifs will make the library management almost impossible. (The conditional compilation is meant to keep compatibility with the current userbase) Unity has this helper class as well, that allows suspending a Coroutine using any custom logic: https://docs.unity3d.com/ScriptReference/CustomYieldInstruction.html I can definetely take the most processing-intensive methods and convert them to Coroutines, but because all the Coroutine chain is made using IEnumerators, that would require converting all methods on the stack as well. What would you guys use to handle such situation? Something that injects code or dependencies came to my mind, but I'm not sure, as I haven't made anything like that yet.
3 Replies
Tvde1
Tvde12y ago
Maybe try the $unity discord? They must surely have tackled this problem many times before
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server