Example #1
0
        /// <summary>
        /// RegisterAsyncTask registers an TPL/Async method that runs when a
        /// Command gets executed and returns no result.
        /// </summary>
        /// <param name="calculationFunc">The function to be run in the
        /// background.</param>
        /// <returns>An Observable that signals when the Task completes, on
        /// the UI thread.</returns>
        public static IObservable <Unit> RegisterAsyncTask(this IReactiveCommand This, Func <object, Task> calculationFunc)
        {
            Contract.Requires(calculationFunc != null);

            // NB: This PermaRef isn't exactly correct, but the people using
            // this method probably are Doing It Wrong, so let's let them
            // continue to do so.
            return(This.RegisterAsync(x => calculationFunc(x).ToObservable())
                   .Publish().PermaRef());
        }
Example #2
0
        /// <summary>
        /// RegisterAsyncFunction registers an asynchronous method that returns a result
        /// to be called whenever the Command's Execute method is called.
        /// </summary>
        /// <param name="calculationFunc">The function to be run in the
        /// background.</param>
        /// <param name="scheduler"></param>
        /// <returns>An Observable that will fire on the UI thread once per
        /// invoecation of Execute, once the async method completes. Subscribe to
        /// this to retrieve the result of the calculationFunc.</returns>
        public static IObservable <TResult> RegisterAsyncFunction <TResult>(this IReactiveCommand This,
                                                                            Func <object, TResult> calculationFunc,
                                                                            IScheduler scheduler = null)
        {
            Contract.Requires(calculationFunc != null);

            var asyncFunc = calculationFunc.ToAsync(scheduler ?? RxApp.TaskpoolScheduler);

            return(This.RegisterAsync(asyncFunc));
        }
Example #3
0
 /// <summary>
 /// RegisterAsyncTask registers an TPL/Async method that runs when a
 /// Command gets executed and returns the result
 /// </summary>
 /// <returns>An Observable that will fire on the UI thread once per
 /// invoecation of Execute, once the async method completes. Subscribe to
 /// this to retrieve the result of the calculationFunc.</returns>
 public static IObservable <TResult> RegisterAsyncTask <TResult>(this IReactiveCommand This, Func <object, Task <TResult> > calculationFunc)
 {
     Contract.Requires(calculationFunc != null);
     return(This.RegisterAsync(x => calculationFunc(x).ToObservable()));
 }