Skip to content

Commit

Permalink
fix: only delay promise resolution when needed (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni authored Mar 18, 2022
1 parent 3e318c1 commit f46c425
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NativeScript/NativeScript-Prefix.pch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef NativeScript_Prefix_pch
#define NativeScript_Prefix_pch

#define NATIVESCRIPT_VERSION "8.2.1"
#define NATIVESCRIPT_VERSION "8.2.2-alpha.0"

#ifdef DEBUG
#define SIZEOF_OFF_T 8
Expand Down
22 changes: 18 additions & 4 deletions NativeScript/runtime/PromiseProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
let promise = new target(function(resolve, reject) {
origFunc(value => {
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, resolve.bind(this, value));
CFRunLoopWakeUp(runloop);
const resolveCall = resolve.bind(this, value);
if (runloop === CFRunLoopGetCurrent()) {
resolveCall();
} else {
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, resolveCall);
CFRunLoopWakeUp(runloop);
}
}, reason => {
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, reject.bind(this, reason));
CFRunLoopWakeUp(runloop);
const rejectCall = reject.bind(this, reason);
if (runloop === CFRunLoopGetCurrent()) {
rejectCall();
} else {
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, rejectCall);
CFRunLoopWakeUp(runloop);
}
});
});
Expand All @@ -32,6 +42,10 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
return orig.bind(target);
}
return typeof orig === 'function' ? function(x) {
if (runloop === CFRunLoopGetCurrent()) {
orig.bind(target, x)();
return target;
}
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, orig.bind(target, x));
CFRunLoopWakeUp(runloop);
return target;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nativescript/ios",
"description": "NativeScript Runtime for iOS",
"version": "8.2.1",
"version": "8.2.2-alpha.0",
"keywords": [
"NativeScript",
"iOS",
Expand Down

0 comments on commit f46c425

Please sign in to comment.