Skip to content

Commit

Permalink
Update ReanimatedModuleProxy.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon20000 authored Nov 28, 2024
1 parent 0b4079d commit 1961aac
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,20 @@ jsi::Value ReanimatedModuleProxy::executeOnUIRuntimeSync(
std::mutex mutex;
std::condition_variable cv;
bool taskCompleted = false;
jsi::Value result;
std::shared_ptr<Shareable> shareableResult;

// Schedule the worklet on the UI thread
uiScheduler_->scheduleOnUI([&] {

// Execute the worklet within the UI runtime
jsi::Value workletResult = uiWorkletRuntime_->executeSync(rt, worklet);

auto result = uiWorkletRuntime_->runGuarded(shareableWorklet);
shareableResult = extractShareableOrThrow(uiWorkletRuntime_->getJSIRuntime(), result);


// Lock the mutex, store the result, and notify the waiting thread
{
std::lock_guard<std::mutex> lock(mutex);
result = std::move(workletResult);
taskCompleted = true;
}
cv.notify_one();
Expand All @@ -264,8 +266,10 @@ jsi::Value ReanimatedModuleProxy::executeOnUIRuntimeSync(
cv.wait(lock, [&]() { return taskCompleted; });
}

jsi::Value workletResult = shareableResult->toJSValue(rt);

// Return the result to the calling thread
return result;
return workletResult;
}

jsi::Value ReanimatedModuleProxy::createWorkletRuntime(
Expand Down

0 comments on commit 1961aac

Please sign in to comment.