RaidZeroLib
Coroutine robot framework for VEX V5
Loading...
Searching...
No Matches
rz::Runtime Class Reference

The single-threaded tick loop that drives every coroutine. More...

#include <Runtime.hpp>

Classes

struct  Config

Public Member Functions

 Runtime (Platform &platform)
 Runtime (Platform &platform, Config config)
 ~Runtime ()
 Runtime (const Runtime &)=delete
Runtime & operator= (const Runtime &)=delete
template<class Awaitable>
decltype(auto) run (Awaitable &&task)
 Runs task on this runtime until it completes and returns its result.
Time now () const noexcept
 Time at the start of the current tick.
Duration dt () const noexcept
 Time between the start of the previous tick and this one.
std::uint64_t tickCount () const noexcept
 Number of ticks started so far (0 before the first tick).
Duration period () const noexcept
CompetitionMode competitionMode () const
 The competition mode field control is in right now.

Static Public Member Functions

static Runtime & current ()
 The runtime that exists right now. Only one can exist at a time.
static Runtime * tryCurrent () noexcept
 The current runtime, or nullptr if none exists (e.g. while globals are being constructed).
static std::uint64_t globalTickId () noexcept
 Identifies the current tick uniquely across every runtime there has been; never repeats. Use it as the key for per-tick caches (a new runtime restarts tickCount() at 0).

Friends

class TickAwaiter
class SleepAwaiter
struct corral::EventLoopTraits< Runtime >

Detailed Description

The single-threaded tick loop that drives every coroutine.

Each tick, in order: resume TickStarted waiters, SensorsUpdated waiters, expired timers, EstimatorsUpdated waiters, then ComponentsUpdated waiters, then sleep until the next period. Within a stage, waiters resume in the order they started waiting, so loops that wait once per tick keep their order from tick to tick. A coroutine that waits again while its stage is being resumed lands in the next tick, so no loop can run twice in one tick.

It is corral's event loop: runtime.run(task) runs task to completion.

Constructor & Destructor Documentation

◆ Runtime() [1/3]

rz::Runtime::Runtime ( Platform & platform)
inlineexplicit

◆ Runtime() [2/3]

rz::Runtime::Runtime ( Platform & platform,
Config config )

◆ ~Runtime()

rz::Runtime::~Runtime ( )

◆ Runtime() [3/3]

rz::Runtime::Runtime ( const Runtime & )
delete

Member Function Documentation

◆ competitionMode()

CompetitionMode rz::Runtime::competitionMode ( ) const
inlinenodiscard

The competition mode field control is in right now.

◆ current()

Runtime & rz::Runtime::current ( )
staticnodiscard

The runtime that exists right now. Only one can exist at a time.

◆ dt()

Duration rz::Runtime::dt ( ) const
inlinenodiscardnoexcept

Time between the start of the previous tick and this one.

◆ globalTickId()

std::uint64_t rz::Runtime::globalTickId ( )
inlinestaticnodiscardnoexcept

Identifies the current tick uniquely across every runtime there has been; never repeats. Use it as the key for per-tick caches (a new runtime restarts tickCount() at 0).

◆ now()

Time rz::Runtime::now ( ) const
inlinenodiscardnoexcept

Time at the start of the current tick.

◆ operator=()

Runtime & rz::Runtime::operator= ( const Runtime & )
delete

◆ period()

Duration rz::Runtime::period ( ) const
inlinenodiscardnoexcept

◆ run()

template<class Awaitable>
decltype(auto) rz::Runtime::run ( Awaitable && task)

Runs task on this runtime until it completes and returns its result.

◆ tickCount()

std::uint64_t rz::Runtime::tickCount ( ) const
inlinenodiscardnoexcept

Number of ticks started so far (0 before the first tick).

◆ tryCurrent()

Runtime * rz::Runtime::tryCurrent ( )
inlinestaticnodiscardnoexcept

The current runtime, or nullptr if none exists (e.g. while globals are being constructed).

◆ corral::EventLoopTraits< Runtime >

friend struct corral::EventLoopTraits< Runtime >
friend

◆ SleepAwaiter

friend class SleepAwaiter
friend

◆ TickAwaiter

friend class TickAwaiter
friend

The documentation for this class was generated from the following file: