public interface ChannelId<T>
channelswhich are used for communication between
coroutines. One possible usage would be to implement it on enums or similar constants that are to be used as channel IDs. To simplify typed lookup of channels IDs are generically typed with the datatype of the target channel. Either implementations or application are responsible that their channel IDs are unique also with respect to the datatype.
Instances of a default implementation of string-based IDs can be created
through the generic factory method
channel(String, Class). Please
check the method comment for informations about the constraints imposed by
that implementation. There are also some derived factory methods for common
|Modifier and Type||Interface and Description|
Internal implementation of string-based channel IDs.
|Modifier and Type||Method and Description|
Creates a channel ID with a boolean datatype.
Creates a new channel ID from an identifier string.
Creates a channel ID with an integer datatype.
Creates a channel ID with a string datatype.
static ChannelId<java.lang.Boolean> booleanChannel(java.lang.String sId)
sId- The ID string
static <T> ChannelId<T> channel(java.lang.String sId, java.lang.Class<T> rDatatype)
CoroutineContext. IDs aren't cached so that invocations with the the same string and datatyoe will return different instances which are considered equal (see below). To avoid name clashes in complex scenarios the ID names should be selected appropriately, e.g. by using namespaces. The implementation doesn't impose any restrictions on the strings used to define IDs.
Equality of string-based IDs is also based on the datatype. That means
that it is possible to create equal-named channel IDs for different
datatypes. Accessing channels through such IDs would yield different
channel instances but that usage is not recommended. It lies in the
responsibility of the application to name channel IDs appropriately for
the respective context (or provide it's own
sId- The channel ID string
rDatatype- The class of the channel datatype to ensure
static ChannelId<java.lang.Integer> intChannel(java.lang.String sId)
sId- The ID string