scenery
scenery copied to clipboard
Reduce `GlobalScope` usage
For concurrency, scenery uses GlobalScope
is a few places, which is discouraged now.
A better solution for this needs to be found. Maybe @elect86 or @altavir have suggestions 😎
I wish I could help with coroutines, but I still haven't used them enough to be familiar with :/
The GlobalScope is indeed a bad practice. The good practice is to create a scope for your application and pass it explicitly where you need it. Could you give links to places in question, or we can plan an online session to discuss that.
https://github.com/scenerygraphics/scenery/blob/795acc388ac1665ef1bb3bc417418dab030b7d38/src/main/kotlin/graphics/scenery/DefaultNode.kt#L61
How about this one? The intention there is to invoke a lambda asynchronously when a new Node is added.
Edit: Pasted wrong URL first. D'oh.
I don't understand what this line does. Looks like it just assigned a field to itself.
You probably wanted to link to something like
https://github.com/scenerygraphics/scenery/blob/f6aedc19714d899b316235b53dc3d5c0b44bf83a/src/main/kotlin/graphics/scenery/DefaultNode.kt#L61
And it is indeed not good. If the process is long, the structured concurrency is broken here. You need to provide a scope for such operations. Pass it as a parameter or store it in the Node
.