public WaitHandle RegisterWaitHandler(ResultFilter filter) { var waitEvent = new ManualResetEvent(false); var registeredWait = new RegisteredResultWait(filter, waitEvent); var handle = new WaitHandle(); if (!this.waits.TryAdd(handle, registeredWait)) { throw new InvalidOperationException("Wait is already registered"); } return handle; }
/// <summary> /// Initializes a new instance of the <see cref="RegisteredResultWait"/> class. /// </summary> /// <param name="filter"> /// The filter. /// </param> /// <param name="waitEvent"> /// The wait event. /// </param> internal RegisteredResultWait(ResultFilter filter, ManualResetEvent waitEvent) { this.Filter = filter; this.WaitEvent = waitEvent; }
/// <summary> /// Registers a callback. This will be called when the result of a function is found that matches the filter /// </summary> /// <param name="filter"> /// The filter to determine the matching result /// </param> /// <param name="callback"> /// The function to call when the result is received /// </param> public void RegisterResultCallback(ResultFilter filter, ResultCallback callback) { if (!this.callbacks.TryAdd(new RegisteredResultCallback(filter, callback), 0)) { throw new InvalidOperationException("Could not register callback"); } }