mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
642 stars 22 forks source link

fix: Fix `Promise::awaitFuture` actually locking threads #347

Closed mrousavy closed 3 days ago

mrousavy commented 3 days ago

Fixes an issue where the new Promise<T> implementation introduced in https://github.com/mrousavy/nitro/commit/8832bc5225353e9ac0905c9a51cc57bf3dc1f076 actually caused a thread-lock since std::future was still used. This caused the future to be awaited on the JS thread instead of the background thread, making promises resolve synchronously instead of asynchronously.

The issue was caused by std::future/std::shared_future's RAII mechanism where the destructor waits for the task to complete. Now, it is moved to a shared_ptr and only awaited for completion in the run function.

vercel[bot] commented 3 days ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **nitro-docs** | ⬜️ Skipped ([Inspect](https://vercel.com/margelo/nitro-docs/95F7JFLSvbDZ8aH1p9oVRjMP3Vwr)) | | | Nov 18, 2024 11:52pm |