Upgrade to v0.12
In Xronos v0.12, the timing API moved from the reactor to the reaction.
The old reactor-level API still works in v0.12 but is deprecated and will be removed in a future release, so you are encouraged to migrate.
Python SDK
Reaction declarations receive a ReactionContext
Reactions now receive a ReactionContext instead of a
ReactionInterface. The conventional parameter name changes from
interface to ctx. Use it to declare triggers and effects exactly as before.
Before (v0.11):
@xronos.reaction
def on_timer(self, interface: xronos.ReactionInterface) -> Callable[[], None]:
timer = interface.add_trigger(self.timer)
output = interface.add_effect(self.output)
...
After (v0.12):
@xronos.reaction
def on_timer(self, ctx: xronos.ReactionContext) -> Callable[[], None]:
timer = ctx.add_trigger(self.timer)
output = ctx.add_effect(self.output)
...
Read the time from the reaction context
The current_time,
lag, and
elapsed_time attributes are now read from
the ctx object instead of from self (the reactor). The reaction handler is a
closure, so it captures ctx from the surrounding declaration.
Before (v0.11):
@xronos.reaction
def on_timer(self, interface: xronos.ReactionInterface) -> Callable[[], None]:
interface.add_trigger(self.timer)
def handler() -> None:
now = self.get_time()
lag = self.get_lag()
elapsed = self.get_time_since_startup()
...
return handler
After (v0.12):
@xronos.reaction
def on_timer(self, ctx: xronos.ReactionContext) -> Callable[[], None]:
ctx.add_trigger(self.timer)
def handler() -> None:
now = ctx.current_time
lag = ctx.lag
elapsed = ctx.elapsed_time
...
return handler
Migrate incrementally
ReactionContext is a subclass of
ReactionInterface, so reactions whose parameter is still
annotated ReactionInterface keep type-checking and run unchanged. You can
therefore migrate one reaction at a time: switch the annotation to
ReactionContext (and read the time via ctx) only where you need it.
C++ SDK
Read the time from within the reaction
The current_time(),
lag(), and
elapsed_time()
methods are now members of BaseReaction.
Call them directly inside a reaction handler instead of through
self() (the reactor).
Before (v0.11):
void handler() final {
auto now = self().get_time();
auto current_lag = self().get_lag();
auto elapsed = self().get_time_since_startup();
...
}
After (v0.12):
void handler() final {
auto now = current_time();
auto current_lag = lag();
auto elapsed = elapsed_time();
...
}
Rename remaining_slack() to slack()
The remaining_slack()
method was renamed to
slack(). The old name is
deprecated and will be removed in a future release.
// before
auto s = remaining_slack();
// after
auto s = slack();