Example #1
0
        /// <summary>
        /// Registers the provided <see cref="Action{T}"/> to receive callbacks of type <typeparamref name="TCallback" />.
        /// </summary>
        /// <param name="jobID">The <see cref="JobID"/> of the callbacks that should be subscribed to.
        ///		If this is <see cref="JobID.Invalid"/>, all callbacks of type <typeparamref name="TCallback" /> will be recieved.</param>
        /// <param name="callbackFunc">The function to invoke with the callback.</param>
        /// <typeparam name="TCallback">The type of callback to subscribe to.</typeparam>
        /// <returns>An <see cref="IDisposable"/>. Disposing of the return value will unsubscribe the <paramref name="callbackFunc"/>.</returns>
        public IDisposable Subscribe <TCallback>(JobID jobID, Action <TCallback> callbackFunc)
            where TCallback : class, ICallbackMsg
        {
            var callback = new Internal.Callback <TCallback>(callbackFunc, this, jobID);

            return(new Subscription(callback, this));
        }
Example #2
0
        /// <summary>
        /// Registers the provided <see cref="Action{T}"/> to receive callbacks of type <typeparamref name="TCallback" />.
        /// </summary>
        /// <param name="jobID">The <see cref="JobID"/> of the callbacks that should be subscribed to.
        ///		If this is <see cref="JobID.Invalid"/>, all callbacks of type <typeparamref name="TCallback" /> will be recieved.</param>
        /// <param name="callbackFunc">The function to invoke with the callback.</param>
        /// <typeparam name="TCallback">The type of callback to subscribe to.</typeparam>
        /// <returns>An <see cref="IDisposable"/>. Disposing of the return value will unsubscribe the <paramref name="callbackFunc"/>.</returns>
        public IDisposable Subscribe <TCallback>(JobID jobID, Action <TCallback> callbackFunc)
            where TCallback : class, ICallbackMsg
        {
            if (jobID == null)
            {
                throw new ArgumentNullException(nameof(jobID));
            }

            if (callbackFunc == null)
            {
                throw new ArgumentNullException(nameof(callbackFunc));
            }

            var callback = new Internal.Callback <TCallback>(callbackFunc, this, jobID);

            return(new Subscription(callback, this));
        }