File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ static assert(isObservable!(ObservableSource!int));
137137
138138/* * Extracts the event tyoe of an observable.
139139*/
140- alias ObservableType (O) = typeof (O.Event.init.eventValue );
140+ alias ObservableType (O) = TypeOf ! (O.Event.Kind.event );
141141
142142
143143/* * The fundamental source for generating observable events.
@@ -725,6 +725,7 @@ private struct ObserverNamedTypes(TYPES...)
725725 `MonoTime` timestamp of the original occurrence of each event.
726726*/
727727auto timestamp (O)(ref O source)
728+ if (isObservable! O)
728729{
729730 import core.time : MonoTime;
730731 alias T = ObservableType! O;
@@ -738,6 +739,25 @@ struct TimestampedEvent(T)
738739 MonoTime timestamp;
739740}
740741
742+ unittest {
743+ import core.time : MonoTime, seconds;
744+ import vibe.core.core : runTask;
745+
746+ MonoTime now = MonoTime.currTime();
747+
748+ ObservableSource! int source;
749+
750+ runTask({
751+ source.put(1 );
752+ source.close();
753+ });
754+
755+ foreach (el; source.timestamp.subscribe) {
756+ assert (el.event == 1 );
757+ assert (el.timestamp >= now && el.timestamp <= now + 1. seconds);
758+ }
759+ }
760+
741761
742762/* * Forwards the events emitted by an observable with a fixed delay.
743763*/
You can’t perform that action at this time.
0 commit comments