mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
react-native | Allow invoking a sync callback under AsyncCallback via 'unsafeCallSync'. (#43143)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43143 AsyncCallback allows storing SyncCallback and invoking it from any thread. However, there are cases where if you have a mix of sync and async callbacks - you might want to invoke them together in one go, instead of spreading them out across thread invocations. For those cases - allow invoking any AsyncCallback as a sync one, prefixing it with "unsafe", because it's inherently not a safe operation to perform. Changelog: [General][Changed] - Allow invoking the AsyncCallback synchronously to allow for tight performance optimization. Reviewed By: s-rws Differential Revision: D54028850 fbshipit-source-id: f6729819f791f1d58d2ca655d4082547f18bdd2d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a1171f79f8
commit
765e542c8d
@@ -54,6 +54,15 @@ class AsyncCallback {
|
||||
callWithFunction(priority, std::move(callImpl));
|
||||
}
|
||||
|
||||
/// Invoke the function write-away as if it was a synchronous function
|
||||
/// without any synchronization or delegating to JS context.
|
||||
/// @note Caller is responsible for calling this from within JS context.
|
||||
void unsafeCallSync(Args... args) const noexcept {
|
||||
if (callback_) {
|
||||
(*callback_)(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
friend Bridging<AsyncCallback>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user