forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] More spec-compliant execution of microtasks
Summary: Changelog: [internal] This modifies the method to run microtasks in `RuntimeScheduler_Modern` to align a bit better with the spec. In this case, we'll check if we're already running microtasks when we call that method, and skip if that's the case. We're not currently calling this method recursively so this shouldn't really be a change with the current logic. Differential Revision: D54302537
- Loading branch information
1 parent
7cfd686
commit 04bd850
Showing
3 changed files
with
92 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/react-native/ReactCommon/react/utils/SetForScope.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace facebook::react { | ||
|
||
template <typename T> | ||
class SetForScope { | ||
public: | ||
explicit SetForScope(T& variable) | ||
: variable_(variable), valueToRestore_(variable) {} | ||
|
||
template <typename U> | ||
SetForScope(T& variable, U&& newValue) : SetForScope(variable) { | ||
variable_ = std::forward<U>(newValue); | ||
} | ||
|
||
template <typename U, typename V> | ||
SetForScope(T& variable, U&& newValue, V&& valueToRestore) | ||
: variable_(variable), valueToRestore_(std::forward<V>(valueToRestore)) { | ||
variable_ = std::forward<U>(newValue); | ||
} | ||
|
||
// Non-movable | ||
SetForScope(const SetForScope&) = delete; | ||
SetForScope(SetForScope&&) = delete; | ||
|
||
// Non-copyable | ||
SetForScope& operator=(const SetForScope&) = delete; | ||
SetForScope& operator=(SetForScope&&) = delete; | ||
|
||
~SetForScope() { | ||
variable_ = std::move(valueToRestore_); | ||
} | ||
|
||
private: | ||
T& variable_; | ||
T valueToRestore_; | ||
}; | ||
|
||
} // namespace facebook::react |