|
| 1 | +# API Reference |
| 2 | + |
| 3 | +## CoContext |
| 4 | + |
| 5 | +| Method | Returns | Description | |
| 6 | +|---|---|---| |
| 7 | +| `create_task(task)` | `Task<T>` | Start a coroutine | |
| 8 | +| `subscribe<MsgT>(topic, qos)` | `shared_ptr<TopicStream<MsgT>>` | Subscribe to a topic | |
| 9 | +| `create_timer(period)` | `shared_ptr<TimerStream>` | Create a periodic timer stream | |
| 10 | +| `create_service<SrvT>(name, cb)` | `shared_ptr<Service<SrvT>>` | Create a coroutine service server | |
| 11 | +| `create_action_server<ActT>(name, cb)` | `shared_ptr<Server<ActT>>` | Create a coroutine action server | |
| 12 | +| `wait_for_service(client, timeout)` | *awaitable* `Result<void>` | Wait for a service | |
| 13 | +| `send_request<SrvT>(client, req)` | *awaitable* `Response` | Call a service | |
| 14 | +| `wait_for_action(client, timeout)` | *awaitable* `Result<void>` | Wait for an action server | |
| 15 | +| `send_goal<ActT>(client, goal)` | *awaitable* `Result<shared_ptr<GoalStream>>` | Send an action goal | |
| 16 | +| `sleep(duration)` | *awaitable* `void` | Async sleep | |
| 17 | +| `poll_until(pred, interval, timeout)` | `Task<Result<void>>` | Poll until predicate is true or timeout | |
| 18 | +| `wait_for(awaitable, timeout)` | `Task<Result<T>>` | Race an awaitable against a timeout | |
| 19 | +| `post(fn)` | `void` | Post a callback to the executor thread (thread-safe) | |
| 20 | +| `node()` | `Node&` | Access the underlying node | |
| 21 | + |
| 22 | +## Free Functions |
| 23 | + |
| 24 | +| Function | Returns | Description | |
| 25 | +|---|---|---| |
| 26 | +| `create_single_goal_action_server<ActT>(ctx, name, cb)` | `shared_ptr<Server<ActT>>` | Single-goal action server with preemption | |
| 27 | +| `when_all(awaitables...)` | *awaitable* `tuple<Ts...>` | Await all tasks/awaitables concurrently | |
| 28 | +| `when_any(awaitables...)` | *awaitable* `variant<Ts...>` | Race tasks/awaitables, return first result | |
| 29 | +| `shield(task)` | *awaitable* `T` | Protect a task from parent cancellation | |
| 30 | + |
| 31 | +## Task |
| 32 | + |
| 33 | +| Method | Returns | Description | |
| 34 | +|---|---|---| |
| 35 | +| `operator bool()` | `bool` | `true` if the task holds a valid coroutine (not moved-from) | |
| 36 | +| `done()` | `bool` | `true` if the coroutine has completed (`false` for null tasks) | |
| 37 | +| `result()` | `T&` | Get the result of a completed `Task<T>` (rethrows if exception) | |
| 38 | +| `cancel()` | `void` | Request cancellation via `CancelledException` | |
| 39 | + |
| 40 | +## Result |
| 41 | + |
| 42 | +| Method | Returns | Description | |
| 43 | +|---|---|---| |
| 44 | +| `ok()` | `bool` | `true` if the operation succeeded | |
| 45 | +| `timeout()` | `bool` | `true` if the operation timed out | |
| 46 | +| `value` | `std::optional<T>` | The result value (present when `ok()` is `true`) | |
| 47 | + |
| 48 | +## GoalContext |
| 49 | + |
| 50 | +| Method | Returns | Description | |
| 51 | +|---|---|---| |
| 52 | +| `goal()` | `const Goal&` | Access the goal request | |
| 53 | +| `is_canceling()` | `bool` | Check if cancellation was requested | |
| 54 | +| `publish_feedback(fb)` | `void` | Send feedback to the client | |
| 55 | +| `abort()` | `void` | Abort the goal | |
| 56 | + |
| 57 | +## Event |
| 58 | + |
| 59 | +| Method | Returns | Description | |
| 60 | +|---|---|---| |
| 61 | +| `set()` | `void` | Signal the event, resuming all waiters | |
| 62 | +| `clear()` | `void` | Reset the event so future `wait()` calls will suspend | |
| 63 | +| `wait()` | *awaitable* `void` | Suspends until the event is set | |
| 64 | +| `is_set()` | `bool` | Check the current state | |
| 65 | + |
| 66 | +## Mutex |
| 67 | + |
| 68 | +| Method | Returns | Description | |
| 69 | +|---|---|---| |
| 70 | +| `lock()` | *awaitable* `void` | Suspends until the lock is acquired | |
| 71 | +| `unlock()` | `void` | Release the lock, resuming the next waiter | |
| 72 | +| `is_locked()` | `bool` | Check the current state | |
| 73 | + |
| 74 | +## Channel |
| 75 | + |
| 76 | +| Method | Returns | Description | |
| 77 | +|---|---|---| |
| 78 | +| `send(value)` | `void` | Send a value (thread-safe) | |
| 79 | +| `close()` | `void` | Signal end of stream | |
| 80 | +| `next()` | *awaitable* `optional<T>` | Receive the next value (`nullopt` when closed) | |
| 81 | + |
| 82 | +## TfBuffer |
| 83 | + |
| 84 | +| Method | Returns | Description | |
| 85 | +|---|---|---| |
| 86 | +| `TfBuffer(ctx)` | -- | Construct with a `CoContext`; starts a listener thread | |
| 87 | +| `lookup_transform(target, source)` | `optional<TransformStamped>` | Sync lookup of latest transform | |
| 88 | +| `lookup_transform(target, source, time)` | *awaitable* `TransformStamped` | Async lookup; suspends until available | |
0 commit comments