command_sender
Schedules admission and receiver completion on the supplied scheduler.
Source and package
- Qualified name
-
libtmux::command _sender - Namespace
- libtmux
- Package
- libtmux-cxx
- Source
- include/libtmux/execution.hpp
- template <stdexec::scheduler Scheduler> [[
C++ nodiscard attributeAsks the compiler to warn when a result is discarded. An explicit cast to void acknowledges that the result is intentionally ignored.]] auto command_sender(Scheduler scheduler, const Server& server, CommandRuntime & runtime, CommandRequest request, stdexec::inplace_stop_token stop = {}); -
Description
A scheduler that dispatches on another thread must return from posting the work without waiting for the receiver. Inline completion is supported. The runtime hands off an admitted result from its completion thread. An inline scheduler can run a receiver on that thread. Receivers running there must return promptly and arrange runtime shutdown on another thread.
Owns the server and request. The connected operation owns the receiver. Keep the operation state alive until receiver completion begins. Keep the runtime, scheduler and explicit stop source alive through completion, even if
CommandRuntime::close()has already returned.The value channel carries the output string. The error channel carries
CommandFailure, including delivery information, orstd::exception_ptr. The scheduler can also stop admission or delivery. Admission forwards scheduler errors. Delivery scheduling errors usestd::exception_ptr. Receiver stop can stop admission or request transport cancellation after admission. The optional explicit token also requests transport cancellation. Global observers still requireCommandRuntime::dispatch_ready().Run example.
- Type parameters
-
-
Constraint stdexec::scheduler
-
- Parameters
-
-
stop(stdexec::inplace_stop_token)Default
{}
Examples
Fetch the library version documented on this page.
Terminal window $ git clone https://github.com/libtmux/libtmux-cxx.git libtmux-source && \git -C libtmux-source checkout 75ff8098f8b2a6d7690962ba82087b19d086b5b8Build and run the optional sender example on POSIX. The linked guide also covers installed packages, cancellation and shutdown. View source
Terminal window $ cd libtmux-source$ cmake -S . \-B build/command-senders \-DCMAKE_CXX_COMPILER=clang++ \-DCMAKE_CXX_FLAGS=-stdlib=libc++ \-DLIBTMUX_BUILD_TESTS=OFF \-DLIBTMUX_BUILD_EXAMPLES=ON \-DLIBTMUX_EXAMPLES_BUILD_EXECUTION=ON \-DLIBTMUX_FETCH_DEPS=ON$ cmake --build build/command-senders \--target libtmux_example_09_command_senders$ ./build/command-senders/examples/libtmux_example_09_command_sendersWhile tmux waits for a signal, the same scheduler worker can admit the command that sends it. View source
09-command-senders.cppComplete program #include <chrono>#include <exception>#include <future>#include <iostream>#include <tuple>#include <utility>#include <exec/static_thread_pool.hpp>#include <libtmux/batch.hpp>#include <libtmux/execution.hpp>#include <libtmux/testing/scoped_server.hpp>#include <stdexec/execution.hpp>namespace {int report_failure(const libtmux::CommandFailure& failure) {std::cerr << libtmux::to_string(failure) << '\n';return 1;}} // namespaceint main() try {using libtmux::command_sender;using namespace std::chrono_literals;constexpr auto timeout = 5s;auto fixture = libtmux::test::ScopedTmuxServer::start({.socket_namespace = libtmux::test::SocketNamespace::consumer("sender")});if (!fixture) {std::cerr << fixture.error() << '\n';return 1;}const auto& path = fixture->socket_path();auto server = libtmux::Server::at_socket_path(path, {}, {.timeout = timeout});if (!server) {return report_failure(server.error());}exec::static_thread_pool pool{1};auto runtime = libtmux::CommandRuntime::start({.capacity = 2});if (!runtime) {return report_failure(runtime.error());}const auto scheduler = pool.get_scheduler();libtmux::CommandBatch batch;batch.add({"wait-for", "-S", "entered"});batch.add({"wait-for", "release"});batch.add({"display-message", "-p", "tmux released the wait"});auto wait = command_sender(scheduler, *server, *runtime, batch.request());auto wait_future =std::async(std::launch::async, stdexec::sync_wait, std::move(wait));if (auto entered = server->wait_for("entered", timeout); !entered) {return report_failure(entered.error());}libtmux::CommandRequest release{"wait-for", "-S", "release"};const auto signalled = stdexec::sync_wait(command_sender(scheduler, *server, *runtime, std::move(release)));const auto waited = wait_future.get();if (!signalled || !waited) {std::cerr << "a command sender stopped\n";return 1;}if (const auto closed = runtime->close(); closed.failure) {return report_failure(*closed.failure);}std::cout << std::get<0>(*waited);return 0;} catch (const libtmux::CommandFailure& failure) {return report_failure(failure);} catch (const std::exception& failure) {std::cerr << failure.what() << '\n';return 1;}Expected output: View source
09-command-senders.out tmux released the wait
Recorded calls
source callsThe C++ reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls libtmux::command_sender.