Files
react-native/packages/react-native/ReactCommon/react/utils/OnScopeExit.h
T
Rubén Norte 21171222eb 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.

Reviewed By: javache

Differential Revision: D54302537

fbshipit-source-id: ef5e12e68e0c7f8c9258929609c050ef78e4cde5
2024-02-29 11:38:30 -08:00

37 lines
743 B
C++

/*
* 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 <functional>
namespace facebook::react {
template <typename Lambda>
class OnScopeExit {
public:
explicit OnScopeExit(const Lambda&& lambda) noexcept
: lambda_(std::move(lambda)) {}
// Non-movable
OnScopeExit(const OnScopeExit&) = delete;
OnScopeExit(OnScopeExit&&) = delete;
// Non-copyable
OnScopeExit& operator=(const OnScopeExit&) = delete;
OnScopeExit& operator=(OnScopeExit&&) = delete;
~OnScopeExit() noexcept {
lambda_();
}
private:
Lambda lambda_;
};
} // namespace facebook::react