Files
react-native/ReactCommon/hermes/inspector/chrome/tests/SyncConnection.h
T
Will Holen 452cb9a78a Add support for Debugger.runIfWaitingForDebugger
Summary:
This call is used to continue execution when the app has just been
started in a "wait for debugger" mode. This is the only case
in which it has an effect.

Notably, it should do nothing in the following cases, which a layperson
may be tempted to classify as "WaitingForDebugger":

* The app was running detached and hit a 'debugger;' statement
* The app is paused because of a breakpoint or hitting the Pause button
* The app stopped on an instrumentation breakpoint, and expects
  the debugger to collect data and potentially auto-resume.

Changelog: [Internal] Add Hermes support for Debugger.runIfWaitingForDebugger

Reviewed By: mhorowitz

Differential Revision: D21557446

fbshipit-source-id: 790cec7444ddc61908d2ef9d92e4649b535d678f
2020-05-15 12:42:38 -07:00

70 lines
1.8 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its 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 <chrono>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <folly/Function.h>
#include <folly/Optional.h>
#include <hermes/hermes.h>
#include <hermes/inspector/chrome/Connection.h>
namespace facebook {
namespace hermes {
namespace inspector {
namespace chrome {
/**
* SyncConnection provides a synchronous interface over Connection that is
* useful in tests.
*/
class SyncConnection {
public:
SyncConnection(
std::shared_ptr<HermesRuntime> runtime,
bool waitForDebugger = false);
~SyncConnection() = default;
/// sends a message to the debugger
void send(const std::string &str);
/// waits for the next response from the debugger. handler is called with the
/// response. throws on timeout.
void waitForResponse(
folly::Function<void(const std::string &)> handler,
std::chrono::milliseconds timeout = std::chrono::milliseconds(2500));
/// waits for the next notification from the debugger. handler is called with
/// the notification. throws on timeout.
void waitForNotification(
folly::Function<void(const std::string &)> handler,
std::chrono::milliseconds timeout = std::chrono::milliseconds(2500));
private:
class RemoteConnnection;
friend class RemoteConnnection;
void onReply(const std::string &message);
Connection connection_;
std::mutex mutex_;
std::condition_variable hasReply_;
std::queue<std::string> replies_;
std::condition_variable hasNotification_;
std::queue<std::string> notifications_;
};
} // namespace chrome
} // namespace inspector
} // namespace hermes
} // namespace facebook