You write events one at a time using the AtomEventObserver<T>
class.
Events can subsequently be read using the FifoEvents<T>
or LifoEvents<T>
classes.
AtomEventObserver<T>
supports both synchronous and asynchronous writes. Synchronous writes offer the advantage that you can treat AtomEventObserver<T>
as an IObserver<T>
:
IObserver<IUserEvent> obs = new AtomEventObserver<IUserEvent>( eventStreamId, // a Guid pageSize, // an Int32 storage, // an IAtomEventStorage object serializer); // an IContentSerializer object var userCreated = new UserCreated { UserId = eventStreamId, UserName = "ploeh", Password = "12345", Email = "ploeh@fnaah.com" }; obs.OnNext(userCreated);
It's not necessary to explicitly declare obs
as IObserver<IUserEvent>
: you can use the var
keyword as well; this example just uses explicit variable declaration in order to make it clearer what's going on.
When the call to obs.OnNext
returns, the userCreated
event has been written to storage
.
The storage
variable can be any IAtomEventStorage implementation.
The serializer
variable can be any IContentSerializer implementation.
Asynchronous writes can be done using the standard Task Parallel Library (TPL) model for asynchrony:
var obs = new AtomEventObserver<IUserEvent>( eventStreamId, // a Guid pageSize, // an Int32 storage, // an IAtomEventStorage object serializer); // an IContentSerializer object var userCreated = new UserCreated { UserId = eventStreamId, UserName = "ploeh", Password = "12345", Email = "ploeh@fnaah.com" }; await obs.AppendAsync(userCreated);
Notice that since AtomEventObserver<T>
uses the standard TPL model, you can use it with async
and await
.
When the task returned by obs.AppendAsync
completes, the userCreated
event has been written to storage
.
The storage
variable can be any IAtomEventStorage implementation.
The serializer
variable can be any IContentSerializer implementation.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4