示例#1
0
 /// <summary>
 /// Invokes the factory, using the source as input, suppressing any thrown exception.
 /// </summary>
 /// <param name="default">The result value when not successful.</param>
 public static Attempt <TResult> AttemptGet <TSource, TResult>(this TSource source, Func <TSource, TResult> factory,
                                                               TResult @default = default(TResult))
 {
     return(Attempt.Get(() => factory(source)));
 }
示例#2
0
 /// <summary>
 /// Invokes the factory, using the source as input, suppressing any thrown exception.
 /// </summary>
 /// <param name="default">The result value when not successful.</param>
 public static Task <Attempt <TResult> > AttemptGetAsync <TSource, TResult>(this TSource source,
                                                                            Func <TSource, Task <TResult> > factory,
                                                                            TResult @default = default(TResult))
 {
     return(Attempt.GetAsync(() => factory(source)));
 }
示例#3
0
        public static Task <T> StartNew <T>(this TaskFactory taskFactory, Func <T> function, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
        {
            var taskScheduler = Attempt.Get(TaskScheduler.FromCurrentSynchronizationContext).Value ?? TaskScheduler.Default;

            return(taskFactory.StartNew(function, cancellationToken, creationOptions, taskScheduler));
        }