margelo / react-native-worklets-core

🧵 A library to run JS functions ("Worklets") on separate Threads
https://margelo.io
MIT License
578 stars 37 forks source link

feat: Remove singleton pattern #198

Open mrousavy opened 6 months ago

mrousavy commented 6 months ago

Remove the static singleton pattern from the app.

The idea is that we have one default context (one member of WorkletsApi), and everything else is instance based so it has to be passed down to callers.

I also want to add a global.__dispatcher to every Runtime so that it's easy to find your way back into a Runtime after dispatching away from it (e.g. for callbacks or to resolve promises). Those dispatchers can always be held with weak_ptrs, so if they ever go out of scope, you know that the runtime was deleted.