Skip to content

Commit 2bce15f

Browse files
committed
Capture makeScheduler/makeErrorHandler
1 parent e156a44 commit 2bce15f

5 files changed

+34
-7
lines changed

cpp/RNMultithreadingInstaller.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ static std::unique_ptr<reanimated::RuntimeManager> manager;
1717

1818
//reanimated::RuntimeManager manager;
1919

20-
void install(jsi::Runtime& runtime) {
20+
void install(jsi::Runtime& runtime,
21+
std::function<reanimated::Scheduler()> makeScheduler,
22+
std::function<reanimated::ErrorHandler(std::shared_ptr<reanimated::Scheduler>)> makeErrorHandler) {
2123
// Quickly setup the runtime - this is executed in parallel, and _might_ introduce race conditions if spawnThread is called before this finishes.
22-
pool.enqueue([]() {
24+
pool.enqueue([makeScheduler, makeErrorHandler]() {
2325
auto runtime = makeJSIRuntime();
2426
reanimated::RuntimeDecorator::decorateRuntime(*runtime, "CUSTOM_THREAD");
27+
auto scheduler = makeScheduler();
2528
manager = std::make_unique<reanimated::RuntimeManager>(std::move(runtime),
26-
std::shared_ptr<reanimated::ErrorHandler>(),
27-
std::shared_ptr<reanimated::Scheduler>());
29+
makeErrorHandler(scheduler),
30+
scheduler);
2831
});
2932

3033
// spawnThread(run: () => T): Promise<T>

cpp/RNMultithreadingInstaller.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
#pragma once
44
#include <jsi/jsi.h>
5+
#include <RNReanimated/Scheduler.h>
6+
#include <RNReanimated/ErrorHandler.h>
57

68
using namespace facebook;
79

810
namespace mrousavy {
911
namespace multithreading {
1012

11-
void install(jsi::Runtime& runtime);
13+
void install(jsi::Runtime& runtime,
14+
std::function<reanimated::Scheduler()> makeScheduler,
15+
std::function<reanimated::ErrorHandler(std::shared_ptr<reanimated::Scheduler>)> makeErrorHandler);
1216

1317
}
1418
}

example/ios/Podfile.lock

+3-1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ PODS:
269269
- React-perflogger (= 0.64.0)
270270
- React-jsinspector (0.64.0)
271271
- react-native-multithreading (0.1.0):
272+
- React
273+
- React-callinvoker
272274
- React-Core
273275
- React-perflogger (0.64.0)
274276
- React-RCTActionSheet (0.64.0):
@@ -529,7 +531,7 @@ SPEC CHECKSUMS:
529531
React-jsi: 74341196d9547cbcbcfa4b3bbbf03af56431d5a1
530532
React-jsiexecutor: 06a9c77b56902ae7ffcdd7a4905f664adc5d237b
531533
React-jsinspector: 0ae35a37b20d5e031eb020a69cc5afdbd6406301
532-
react-native-multithreading: c3f34452f0e947efa807e631656c468b8151eb41
534+
react-native-multithreading: 875bf964b7e5a173d98cd4eba3bda837fda76079
533535
React-perflogger: 9c547d8f06b9bf00cb447f2b75e8d7f19b7e02af
534536
React-RCTActionSheet: 3080b6e12e0e1a5b313c8c0050699b5c794a1b11
535537
React-RCTAnimation: 3f96f21a497ae7dabf4d2f150ee43f906aaf516f

ios/RNMultithreading.mm

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
#import <React/RCTBridge+Private.h>
55
#import <React/RCTUtils.h>
6+
#import <ReactCommon/RCTTurboModuleManager.h>
67
#import <jsi/jsi.h>
8+
#import <memory>
9+
10+
#import <RNReanimated/REAIOSScheduler.h>
11+
#import <RNReanimated/REAIOSErrorHandler.h>
712

813
using namespace facebook;
914

@@ -26,7 +31,11 @@ - (void)setBridge:(RCTBridge *)bridge
2631
return;
2732
}
2833

29-
mrousavy::multithreading::install(*(jsi::Runtime *)cxxBridge.runtime);
34+
mrousavy::multithreading::install(*(jsi::Runtime *)cxxBridge.runtime, ^{
35+
return std::make_shared<reanimated::REAIOSScheduler>(bridge.jsCallInvoker);
36+
}, ^ (reanimated::Scheduler scheduler) {
37+
return reanimated::REAIOSErrorHandler(scheduler);
38+
});
3039
}
3140

3241
@end

react-native-multithreading.podspec

+9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ Pod::Spec.new do |s|
1313
s.platforms = { :ios => "10.0" }
1414
s.source = { :git => "https://github.com/mrousavy/react-native-multithreading.git", :tag => "#{s.version}" }
1515

16+
s.pod_target_xcconfig = {
17+
"DEFINES_MODULE" => "YES",
18+
"USE_HEADERMAP" => "YES",
19+
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/Headers/Private/React-Core\" "
20+
}
21+
s.requires_arc = true
22+
1623
s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp}"
1724

25+
s.dependency "React-callinvoker"
26+
s.dependency "React"
1827
s.dependency "React-Core"
1928
end

0 commit comments

Comments
 (0)