Available languages: [Python](https://databento.com/docs/api-live/client/live-threaded-block-for-stop.python.md) · [C++](https://databento.com/docs/api-live/client/live-threaded-block-for-stop.cpp.md) · [Rust](https://databento.com/docs/api-live/client/live-threaded-block-for-stop.rust.md) · [Raw](https://databento.com/docs/api-live/client/live-threaded-block-for-stop.raw.md)

Source: https://databento.com/docs/api-live/client/live-threaded-block-for-stop


### LiveThreaded::BlockForStop

Wait for the `record_callback` to return `KeepGoing::Stop` or a timeout is reached.
Normally, the callback thread from [Start](https://databento.com/docs/api-live/client/live-threaded-start.md)
will stop when the `LiveThreaded` instance goes out of scope,
this method allows that to be inverted, preventing the `LiveThreaded` instance from
going out of scope until the `record_callback` signals to do so.

This method is useful for short examples or waiting for a specific event or events
to occur before closing the session.

#### API method

```cpp
void BlockForStop();
KeepGoing BlockForStop(std::chrono::milliseconds timeout);
```

#### Parameters

| Parameter | Type | Description |
| `timeout` | std::chrono::milliseconds | The maximum time to wait for `record_callback` to return `KeepGoing::Stop`. |

#### Returns

If a timeout is specified, returns `KeepGoing::Continue` if the timeout was reached and the callback is continuing to run
or `KeepGoing::Stop` if it stopped.

#### Example usage

```cpp
#include <databento/enums.hpp>
#include <databento/live.hpp>

using namespace databento;

auto client = LiveBuilder{}
                  .SetKey("$YOUR_API_KEY")
                  .SetDataset("EQUS.MINI")
                  .BuildThreaded();
client.Subscribe({"MSFT"}, Schema::Trades, SType::RawSymbol);
client.Start([](const Record& record) {
  if (record.Holds<TradeMsg>()) {
    return KeepGoing::Stop;
  }
  return KeepGoing::Continue;
});
// Wait for first trade
client.BlockForStop();
```
