LiveThreaded::BlockForStop
Wait for the record_callback to return KeepGoing::Stop or a timeout is reached.
Normally, the callback thread from Start
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.
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.
API method
void BlockForStop();
KeepGoing BlockForStop(std::chrono::milliseconds timeout); Example usage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#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();