René's URL Explorer Experiment


Title: Promise never resolves when resolve() is called inside setTimeout from a background thread · Issue #330 · NativeScript/ios · GitHub

Open Graph Title: Promise never resolves when resolve() is called inside setTimeout from a background thread · Issue #330 · NativeScript/ios

X Title: Promise never resolves when resolve() is called inside setTimeout from a background thread · Issue #330 · NativeScript/ios

Description: A common JS pattern for small delays hangs indefinitely on iOS when the Promise is created on a background thread: async function doSomething() { // wait 25ms for some events to propagate await new Promise(resolve => setTimeout(() => res...

Open Graph Description: A common JS pattern for small delays hangs indefinitely on iOS when the Promise is created on a background thread: async function doSomething() { // wait 25ms for some events to propagate await new...

X Description: A common JS pattern for small delays hangs indefinitely on iOS when the Promise is created on a background thread: async function doSomething() { // wait 25ms for some events to propagate await new...

Opengraph URL: https://github.com/NativeScript/ios/issues/330

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Promise never resolves when resolve() is called inside setTimeout from a background thread","articleBody":"A common JS pattern for small delays hangs indefinitely on iOS when the Promise is created on a background thread:\n\n```javascript\nasync function doSomething() {\n    // wait 25ms for some events to propagate\n    await new Promise(resolve => setTimeout(() => resolve(), 25));\n\n    console.log('never reached');\n}\n```\n\nThis happens when native code (e.g. a NativeScript plugin) invokes JS callbacks on a background thread.\n\n## Reproduction\n\nAny native plugin that calls into JS from a background thread can trigger this. Example with a WebSocket delegate:\n\n```\nNative WebSocket library (background thread)\n  │\n  ▼\nPlugin's native callback handler\n  │  (running on background thread)\n  ▼\nNativeScript bridge invokes JS callback\n  │  (acquires V8 locker on this background thread)\n  ▼\nJS event handler runs\n  │\n  ▼\nawait new Promise(resolve => {\n    setTimeout(() => {\n        resolve();  ← never executes\n    }, 25);\n});\n```\n\nThe Promise hangs forever.\n\n## Cause\n\nPromiseProxy.cpp captures `CFRunLoopGetCurrent()` when the Promise is constructed:\nhttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/PromiseProxy.cpp#L16\n\nIf `resolve()` is later called from a different thread, it uses `CFRunLoopPerformBlock` to schedule the actual resolution on the original thread's runloop:\nhttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/PromiseProxy.cpp#L36-L37\n\nThe problem: background threads from dispatch queues or thread pools have dormant runloops. No code is calling `CFRunLoopRun()` on them - they just execute tasks and return to the pool. The scheduled block never gets processed.\n\nMeanwhile, `setTimeout` always fires on `Runtime::RuntimeLoop()`:\nhttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/Timers.cpp#L125\n\nTimers are added to that runloop here:\nhttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/Timers.cpp#L252\n\nThis is typically the main thread (captured at Runtime creation), which is different from the background thread where the Promise was created.\n\nThe flow:\n\n1. JS callback runs on background thread B (V8 locker acquired)\n2. Promise created, PromiseProxy captures thread B's runloop\n3. setTimeout schedules timer on Runtime's runloop (thread A)\n4. Callback completes, thread B returns to pool (runloop dormant)\n5. Timer fires on thread A\n6. resolve() called on thread A\n7. PromiseProxy sees different runloops, uses CFRunLoopPerformBlock to schedule on thread B\n8. Thread B's runloop is dormant - nobody is pumping it\n9. Block sits there forever, Promise never resolves\n\n## Suggested fix\n\nInstead of marshaling to the creation thread's runloop (which may be dormant), marshal to the Runtime's runloop which is always active:\n\n```javascript\n// In PromiseProxy.cpp JS source\nlet runtimeRunloop = __getRuntimeRunloop();  // new global exposing Runtime::RuntimeLoop()\n\norigFunc(value => {\n    if (isFulfilled()) return;\n    let res = resolve;\n    markFulfilled();\n\n    if (runtimeRunloop === CFRunLoopGetCurrent()) {\n        res(value);\n    } else {\n        CFRunLoopPerformBlock(runtimeRunloop, kCFRunLoopDefaultMode, () => res(value));\n        CFRunLoopWakeUp(runtimeRunloop);\n    }\n}, ...);\n```\n\nThis ensures Promise resolution always happens on the Runtime's thread (where timers fire), regardless of which thread created the Promise. The Runtime's runloop is always being pumped, so the block will execute.\n\nThis would require exposing `Runtime::RuntimeLoop()` to JS, perhaps via a global function:\nhttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/Runtime.h#L27","author":{"url":"https://github.com/adrian-niculescu","@type":"Person","name":"adrian-niculescu"},"datePublished":"2025-12-18T16:07:29Z","url":"https://github.com/NativeScript/ios/issues/330"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:23e0de08-4b32-5c43-2ffe-602e3c551504
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9170:1C6C3E:19A8CA2:21CB8DF:6B0143BA
html-safe-nonce515d4c68f7422ef68688d793c5cebf5df921169d76c849fa6ef96c3c3146899a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTcwOjFDNkMzRToxOUE4Q0EyOjIxQ0I4REY6NkIwMTQzQkEiLCJ2aXNpdG9yX2lkIjoiMjc0NzU5OTk0ODA5MzY3MDMzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaccfa9c426bb529f1b9183dcfa754fb1a56b910ef7bf124271e528d2b21fb4ff85
hovercard-subject-tagissue:3743775286
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/ios/330/issue_layout
twitter:imagehttps://opengraph.githubassets.com/eeb08992fedf1064ec838c7ede94aa02ef2f9325e3eb34c99728563b41c87ab4/NativeScript/ios/issues/330
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/eeb08992fedf1064ec838c7ede94aa02ef2f9325e3eb34c99728563b41c87ab4/NativeScript/ios/issues/330
og:image:altA common JS pattern for small delays hangs indefinitely on iOS when the Promise is created on a background thread: async function doSomething() { // wait 25ms for some events to propagate await new...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameadrian-niculescu
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/NativeScript/ios git https://github.com/NativeScript/ios.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id172934359
octolytics-dimension-repository_nwoNativeScript/ios
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id172934359
octolytics-dimension-repository_network_root_nwoNativeScript/ios
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/NativeScript/ios/issues/330#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fios%2Fissues%2F330
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fios%2Fissues%2F330
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=NativeScript%2Fios
Reloadhttps://github.com/NativeScript/ios/issues/330
Reloadhttps://github.com/NativeScript/ios/issues/330
Reloadhttps://github.com/NativeScript/ios/issues/330
NativeScripthttps://github.com/NativeScript
ioshttps://github.com/NativeScript/ios
Codehttps://github.com/NativeScript/ios
Issues56 (56)https://github.com/NativeScript/ios/issues
Pull requests42 (42)https://github.com/NativeScript/ios/pulls
Actionshttps://github.com/NativeScript/ios/actions
Projectshttps://github.com/NativeScript/ios/projects
Security and qualityhttps://github.com/NativeScript/ios/security
Insightshttps://github.com/NativeScript/ios/insights
https://github.com/NativeScript/ios
New issuehttps://github.com/login?return_to=https://github.com/NativeScript/ios/issues/330
New issuehttps://github.com/login?return_to=https://github.com/NativeScript/ios/issues/330
#396https://github.com/NativeScript/ios/pull/396
Promise never resolves when resolve() is called inside setTimeout from a background threadhttps://github.com/NativeScript/ios/issues/330#top
#396https://github.com/NativeScript/ios/pull/396
https://github.com/adrian-niculescu
adrian-niculescuhttps://github.com/adrian-niculescu
on Dec 18, 2025https://github.com/NativeScript/ios/issues/330#issue-3743775286
ios/NativeScript/runtime/PromiseProxy.cpphttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/PromiseProxy.cpp#L16
73332e1https://github.com/NativeScript/ios/commit/73332e13667730b3084aa3dd7973685196efa086
ios/NativeScript/runtime/PromiseProxy.cpphttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/PromiseProxy.cpp#L36-L37
73332e1https://github.com/NativeScript/ios/commit/73332e13667730b3084aa3dd7973685196efa086
ios/NativeScript/runtime/Timers.cpphttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/Timers.cpp#L125
73332e1https://github.com/NativeScript/ios/commit/73332e13667730b3084aa3dd7973685196efa086
ios/NativeScript/runtime/Timers.cpphttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/Timers.cpp#L252
73332e1https://github.com/NativeScript/ios/commit/73332e13667730b3084aa3dd7973685196efa086
ios/NativeScript/runtime/Runtime.hhttps://github.com/NativeScript/ios/blob/73332e13667730b3084aa3dd7973685196efa086/NativeScript/runtime/Runtime.h#L27
73332e1https://github.com/NativeScript/ios/commit/73332e13667730b3084aa3dd7973685196efa086
https://github.com/edusperoni
edusperonihttps://github.com/edusperoni
on Dec 18, 2025https://github.com/NativeScript/ios/issues/330#issuecomment-3671144440
https://github.com/adrian-niculescu
adrian-niculescuhttps://github.com/adrian-niculescu
on Jun 25, 2026https://github.com/NativeScript/ios/issues/330#issuecomment-4803576506
#396https://github.com/NativeScript/ios/pull/396
adrian-niculescuhttps://github.com/adrian-niculescu
on Jun 25, 2026https://github.com/NativeScript/ios/issues/330#event-27221647877
fix: only marshal promise resolution when created on the runtime loophttps://github.com/adrian-niculescu/NativeScript-iOS/commit/79a74fcd1328429944f70fe6c7724b706de0a0d2
https://docs.github.com/articles/closing-issues-via-commit-messages
79a74fchttps://github.com/adrian-niculescu/NativeScript-iOS/commit/79a74fcd1328429944f70fe6c7724b706de0a0d2
edusperonihttps://github.com/edusperoni
completedhttps://github.com/NativeScript/ios/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
721633ahttps://github.com/NativeScript/ios/commit/721633a50ad32c69b20b5016e5ae49f4c6cb03c8
on Jul 8, 2026https://github.com/NativeScript/ios/issues/330#event-27715359711
adrian-niculescuhttps://github.com/adrian-niculescu
on Jul 8, 2026https://github.com/NativeScript/ios/issues/330#event-27737520701
fix: only marshal promise resolution when created on the runtime loop (…https://github.com/adrian-niculescu/NativeScript-iOS/commit/721633a50ad32c69b20b5016e5ae49f4c6cb03c8
…https://github.com/NativeScript/ios/pull/396
https://docs.github.com/articles/closing-issues-via-commit-messages
721633ahttps://github.com/adrian-niculescu/NativeScript-iOS/commit/721633a50ad32c69b20b5016e5ae49f4c6cb03c8
Sign up for freehttps://github.com/signup?return_to=https://github.com/NativeScript/ios/issues/330
Sign in to commenthttps://github.com/login?return_to=https://github.com/NativeScript/ios/issues/330
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.