scenery icon indicating copy to clipboard operation
scenery copied to clipboard

Reduce `GlobalScope` usage

Open skalarproduktraum opened this issue 3 years ago • 5 comments

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 😎

skalarproduktraum avatar Dec 16 '21 09:12 skalarproduktraum

I wish I could help with coroutines, but I still haven't used them enough to be familiar with :/

elect86 avatar Dec 16 '21 09:12 elect86

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.

altavir avatar Dec 16 '21 09:12 altavir

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.

skalarproduktraum avatar Dec 16 '21 13:12 skalarproduktraum

I don't understand what this line does. Looks like it just assigned a field to itself.

altavir avatar Dec 16 '21 13:12 altavir

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.

altavir avatar Dec 16 '21 13:12 altavir