xtra::Actor
custom-derive when themacros
features is enabled.
- Remove
async_trait
macro in favor of async functions in traits (AFIT). This bumps xtra's MSRV to1.75
. MessageChannel
is now astruct
that can be constructed from anAddress
viaMessageChannel::new
or usingFrom
/Into
.- Move event-loop related functions from
Context
to xtra's top-level scope.Context
is now only used within an actor'sHandler
. The default event-loop now lives atxtra::run
, next toxtra::select
,xtra::join
,xtra::yield
. - Redesign "spawn" interface:
Remove
Actor::create
,ActorManager
and extension traits for spawning. Introducextra::spawn_tokio
,xtra::spawn_smol
,xtra::spawn_async_std
andxtra::spawn_wasm_bindgen
. - Previously,
stop_all
would immediately disconnect the address. However,stop_self
done on every actor would actually not do this in one case - if there were a free-floating (not executing an actor event loop) Context. This change bringsstop_all
in line withstop_self
. stop_all
now does not drain all messages when called, and acts just likestop_self
on all active actors.- Rename features from
with-crate-version
to justcrate
. For example,with-tokio-1
has been renamed totokio
. - Sealed
RefCounter
trait.
AddressSink
was removed in favor of usingimpl Trait
for theAddress::into_sink
method.Context::attach_stream
was removed in favor of composingStream::forward
andAddress::into_sink
.KeepRunning
was removed asContext::attach_stream
was its last usage.InstrumentedExt
was removed. All messages are now instrumented automatically wheninstrumentation
is enabled.Message
no longer exists:Return
is now specified on theHandler
trait itself.stopping
has been removed in favour ofstop_self
andstop_all
. If logic to determine if the actor should stop must be executed, it should be done rather at the point of callingstop_{self,all}
.Context::attach
is removed in favor of implementingClone
forContext
. If you want to run multiple actors on aContext
, simply clone it before callingrun
.- Remove
Context::notify_after
without a direct replacement. To delay the sending of a message, users are encouraged to use thesleep
function of their executor of choice and combine it withAddress::send
into a new future. To cancel the sleeping early in case the actor stops, usextra::scoped
. - Remove
Context::notify_interval
without a direct replacement. Users are encouraged to write their own loop within which they callAddress:send
.
- The
SyncHandler
trait has been removed. This simplifies the API and should not change the performance on stable.- How to upgrade: change all implementations of the
SyncHandler
trait to the normalHandler
trait.
- How to upgrade: change all implementations of the
- All
Actor
lifecycle messages are now async. This allows to do more kinds of things in lifecycle methods, while adding no restrictions.- How to upgrade: add
async
to the function definition of all actor lifecycle methods, add#[async_trait::async_trait]
to theimpl Actor
block.
- How to upgrade: add
Actor
now requiresSend
to implement. Previously, the trait itself did not, but using it did requireSend
.- How to upgrade: you probably never had a non-
Send
actor in the first place.
- How to upgrade: you probably never had a non-
- The
{Weak}{Address|MessageChannel}::attach_stream
methods now require that the actor implementsHandler<M>
whereM: Into<KeepRunning> + Send
. This is automatically implemented for()
, returningKeepRunning::Yes
. This allows the user more control over the future spawned byattach_stream
, but is breaking if the message returned did not implementInto<KeepRunning>
.- How to upgrade: implement
Into<KeepRunning>
for all message types used inattach_stream
. To mimic previous behaviour, returnKeepRunning::Yes
in the implementation.
- How to upgrade: implement
Address
andWeakAddress
lost theirSink
implementations. They can now be turned intoSink
s by calling.into_sink()
.- How to upgrade: convert any addresses to be used as sinks into sinks with
.into_sink()
, cloning where necessary.
- How to upgrade: convert any addresses to be used as sinks into sinks with
{Address|MessageChannel}Ext
were removed in favour of inherent implementations,- How to upgrade: in most cases, this will not have broken anything. If it is directly imported, remove the import.
If you need to be generic over weak and strong addresses, be generic over
Address<A, Rc>
whereRc: RefCounter
for addresses and useMessageChannel<M>
trait objects.
- How to upgrade: in most cases, this will not have broken anything. If it is directly imported, remove the import.
If you need to be generic over weak and strong addresses, be generic over
{Weak}MessageChannel
became traits rather than concrete types. In order to use them, simply cast an address to the correct trait object (e.g&addr as &dyn MessageChannel<M>
orBox::new(addr)
). Theinto_channel
andchannel
methods were also removed.- How to upgrade: replace
{into_}channel
calls with casts to trait objects, and replace references to the old types with trait objects, boxed if necessary. If you were using theSink
implementations of these types, first create anAddressSink
through.into_sink()
, and then cast it to aMessageSink
trait object.
- How to upgrade: replace
Address::into_downgraded
was removed. This did nothing different todowngrade
, except dropping the address after the call.- How to upgrade: Simply call
Address::downgrade
, dropping the strong address afterwards if needed.
- How to upgrade: Simply call
- Some types were moved out of the root crate and into modules.
- How to upgrade: search for the type's name in the documentation and refer to it by its new path.
Actor::spawn
andActor::create
now take anOption<usize>
for the mailbox size.- How to upgrade: choose a suitable size of mailbox for each spawn call, or pass
None
to give them unbounded mailboxes.
- How to upgrade: choose a suitable size of mailbox for each spawn call, or pass
- Many context methods now return
Result<..., ActorShutdown>
to represent failures due to the actor having been shut down.
- The
stable
feature was removed.In order to enable the nightly API, enable the newEdit: as of 0.5.0, the nightly API has been removed.nightly
feature.
- The default API of the
Handler
trait has now changed to anasync_trait
so that xtra can compile on stable.- How to upgrade, alternative 1: change the implementations by annotating the implementation with
#[async_trait]
, removingResponder
and makinghandle
anasync fn
which directly returns the message's result. - How to upgrade, alternative 2: if you want to avoid the extra box, you can disable the default
stable
feature in yourCargo.toml
to keep the old API.
- How to upgrade, alternative 1: change the implementations by annotating the implementation with
- Removal of the
with-runtime
feature- How to upgrade: you probably weren't using this anyway, but rather use
with-tokio-*
orwith-async_std-*
instead.
- How to upgrade: you probably weren't using this anyway, but rather use
Address
methods were moved toAddressExt
to accommodate newAddress
types- How to upgrade: add
use xtra::AddressExt
to wherever address methods are used (or, better yet,use xtra::prelude::*
)
- How to upgrade: add
- All
*_async
methods were removed. Asynchronous and synchronous messages now use the same method for everything.- How to upgrade: simply switch from the
[x]_async
method to the[x]
method.
- How to upgrade: simply switch from the
AsyncHandler
was renamed toHandler
, and the oldHandler
toSyncHandler
. Also, aHandler
andSyncHandler
implementation can no longer coexist.- How to upgrade: rename all
Handler
implementations toSyncHandler
, and allAsyncHandler
implementations toHandler
.
- How to upgrade: rename all