1 module cheetah.socketeventchain; 2 3 import cheetah.socketevent; 4 import cheetah.socketeventargs; 5 6 /// Wrapper for a socket event chain. 7 class SocketEventChain(T) { 8 package(cheetah): 9 /// The socket events. 10 SocketEvent!T[] _events; 11 12 private: 13 /// The execution index. 14 size_t _executionIndex; 15 16 public: 17 /** 18 * Creates a new socket event chain. 19 * Params: 20 * events = The events to chain. 21 */ 22 this(SocketEvent!T[] events) { 23 _events = events; 24 } 25 26 /// Moves onto the next socket event. 27 void moveNext() { 28 _executionIndex++; 29 30 if (_executionIndex == _events.length) { 31 _executionIndex = 0; 32 } 33 } 34 35 /* 36 * Operator overload for calling the class as a function. 37 * Params: 38 * e = The event args. 39 */ 40 void opCall(SocketEventArgs!T e) { 41 if (!_events) { 42 return; 43 } 44 45 auto event = _events[_executionIndex]; 46 47 if (event) { 48 event(e); 49 } 50 } 51 }