MainQueueExecutor.mm 704 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #include "MainQueueExecutor.h"
  8. #include <dispatch/dispatch.h>
  9. #include <folly/Indestructible.h>
  10. namespace facebook {
  11. namespace react {
  12. MainQueueExecutor &MainQueueExecutor::instance()
  13. {
  14. static auto instance = folly::Indestructible<MainQueueExecutor>{};
  15. return *instance;
  16. }
  17. void MainQueueExecutor::add(folly::Func function)
  18. {
  19. __block folly::Func blockFunction = std::move(function);
  20. dispatch_async(dispatch_get_main_queue(), ^{
  21. blockFunction();
  22. });
  23. }
  24. } // namespace react
  25. } // namespace facebook