implement support for an asyncronous event type, including publish & subscribe features
haydnv opened this issue · comments
Example use cases:
- scheduling a cron by subscribing to an event published once per second/minute/hour/etc
- training an ML model as a background job by having several hosts calculate & publish error data for a given subset of training data
- notifying a third-party (non-TinyChain) service that a transaction is committed, i.e. a post-transaction hook
A stream is a queue of events and a list of subscribers. The contents of an event are a Tuple
of Value
s. An event may have no content at all (e.g. an event type PageView may simply prompt the subscriber to increment a counter). An event differs from a request in that it is asynchronous–a requestor waits for the request to complete, but an event sender does not wait for the event to be delivered, only acknowledged by the stream which keeps track of subscribers.
Any service method may subscribe to an event stream. A “subscription” is an OpRef
which is used to deliver events, which are then deleted after they have been delivered to all subscribers or after a configured maximum lifetime has elapsed. An event will be delivered to all subscribers as soon as it is received, i.e. the lead host of the transaction in which the event is received.
A stream may implement a background task by subscribing to itself. This is possible because a stream may not consume a self-published event within the same transaction in which the event was published.
Streams will be addressable under the /streams directory in userspace. In the future, live media may be available under the /media directory.