Skip to content

Commit f46c425

Browse files
authored
fix: only delay promise resolution when needed (#154)
1 parent 3e318c1 commit f46c425

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

NativeScript/NativeScript-Prefix.pch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef NativeScript_Prefix_pch
22
#define NativeScript_Prefix_pch
33

4-
#define NATIVESCRIPT_VERSION "8.2.1"
4+
#define NATIVESCRIPT_VERSION "8.2.2-alpha.0"
55

66
#ifdef DEBUG
77
#define SIZEOF_OFF_T 8

NativeScript/runtime/PromiseProxy.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
1717
1818
let promise = new target(function(resolve, reject) {
1919
origFunc(value => {
20-
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, resolve.bind(this, value));
21-
CFRunLoopWakeUp(runloop);
20+
const resolveCall = resolve.bind(this, value);
21+
if (runloop === CFRunLoopGetCurrent()) {
22+
resolveCall();
23+
} else {
24+
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, resolveCall);
25+
CFRunLoopWakeUp(runloop);
26+
}
2227
}, reason => {
23-
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, reject.bind(this, reason));
24-
CFRunLoopWakeUp(runloop);
28+
const rejectCall = reject.bind(this, reason);
29+
if (runloop === CFRunLoopGetCurrent()) {
30+
rejectCall();
31+
} else {
32+
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, rejectCall);
33+
CFRunLoopWakeUp(runloop);
34+
}
2535
});
2636
});
2737
@@ -32,6 +42,10 @@ void PromiseProxy::Init(v8::Local<v8::Context> context) {
3242
return orig.bind(target);
3343
}
3444
return typeof orig === 'function' ? function(x) {
45+
if (runloop === CFRunLoopGetCurrent()) {
46+
orig.bind(target, x)();
47+
return target;
48+
}
3549
CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, orig.bind(target, x));
3650
CFRunLoopWakeUp(runloop);
3751
return target;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nativescript/ios",
33
"description": "NativeScript Runtime for iOS",
4-
"version": "8.2.1",
4+
"version": "8.2.2-alpha.0",
55
"keywords": [
66
"NativeScript",
77
"iOS",

0 commit comments

Comments
 (0)