/// <summary> /// Invoke the <paramref name="action"/> if not null. /// </summary> /// <param name="action">Action to invoke</param> /// <param name="ct">A CanellationToken</param> /// <param name="param">Parameter of action</param> /// <returns></returns> public static async Task SafeInvoke <TParam>(this ActionAsync <TParam> action, CancellationToken ct, TParam param) { if (action != null) { await action(ct, param); } }
/// <summary> /// Invoke the <paramref name="action"/> if not null. /// </summary> /// <param name="action">Action to invoke</param> /// <param name="ct">A CanellationToken</param> /// <returns></returns> public static async Task SafeInvoke(this ActionAsync action, CancellationToken ct) { if (action != null) { await action(ct); } }
public async Task ApplyAsync(ActionAsync action) { if (data?.Any() ?? false) { await action?.Invoke(data[0]); } }
public async Task ForEachAsync(ActionAsync <C> action) //i think done. { foreach (C thisItem in _privateDict.Values) { await action.Invoke(thisItem); } }
public AsyncTestRunner(ActionAsync <AsyncTestRunner> method = null, [CallerMemberName] string name = null, [CallerLineNumber] int line = -1, bool loop = false) { _loop = loop; _identifier = $"{name}@{line}"; ImmutableInterlocked.Update(ref _runners, r => r.Add(this)); if (method != null) { Run(method); } }
public AsyncCommand(ActionAsync <T> execute) : base(async(o) => { if (IsValidParameter(o)) { await execute((T)o); } }) { if (execute == null) { throw new ArgumentNullException(nameof(execute)); } }
/// <summary> /// Constructor using an <see cref="IObjectSerializer"/> for persistence. /// </summary> public LockedFileDataPersister( string fullFilename, IObjectSerializer serializer, int numberOfRetries = 3, int retryDelay = 100) { _committedFile = new FileInfo(fullFilename /*.Validation().NotNull(nameof(fullFilename))*/).FullName; _read = async(ct, stream) => (T)serializer.FromStream(stream, typeof(T)); _write = async(ct, entity, stream) => serializer.WriteToStream(entity, typeof(T), stream, canDisposeStream: true); _numberOfRetries = numberOfRetries; _retryDelay = retryDelay; // Create other working file names _oldFile = _committedFile + ".old"; _newFile = _committedFile + ".new"; _lockFile = _committedFile + ".lck"; }
/// <summary> /// Constructor with callbacks for read & write operations. /// </summary> public LockedFileDataPersister( string fullFilename, FuncAsync <Stream, T> read, ActionAsync <T, Stream> write, int numberOfRetries = 3, int retryDelay = 100) { _committedFile = new FileInfo(fullFilename /*.Validation().NotNull(nameof(fullFilename))*/).FullName; _read = read; _write = write; _numberOfRetries = numberOfRetries; _retryDelay = retryDelay; // Create other working file names _oldFile = _committedFile + ".old"; _newFile = _committedFile + ".new"; _lockFile = _committedFile + ".lck"; }
public Task Run(ActionAsync <AsyncTestRunner> method) { var item = new QueueItem(method); ImmutableInterlocked.Enqueue(ref _queue, item); if (_thread == null) { var thread = new Thread(RunLoop); if (Interlocked.CompareExchange(ref _thread, thread, null) == null) { thread.Start(); } } else { _queueEvent.Set(); } return(item.Task); }
public static ActionAsync CreateAsync(ActionAsync action) { return(action); }
/// <summary> /// Adds a <see cref="AnalyticsDataLoaderStrategy"/> to this builder. /// </summary> /// <typeparam name="TBuilder">The type of the builder.</typeparam> /// <param name="builder">The builder.</param> /// <param name="onSuccess">The callback when the strategy loads successfully.</param> /// <param name="onError">The callback when the strategy fails to load.</param> /// <returns>The original builder.</returns> public static TBuilder WithAnalytics <TBuilder>(this TBuilder builder, ActionAsync <IDataLoaderRequest, object> onSuccess, ActionAsync <IDataLoaderRequest, Exception> onError) where TBuilder : IDataLoaderBuilder { return(builder.WithStrategy(new AnalyticsDataLoaderStrategy(onSuccess, onError))); }
public AnalyticsDataLoaderStrategy(ActionAsync <IDataLoaderRequest, object> onSuccess, ActionAsync <IDataLoaderRequest, Exception> onError) { _onSuccess = onSuccess; _onError = onError; }
CurryLast <T1, T2, T3, T4>(this ActionAsync <T1, T2, T3, T4> action, T4 last) { return((CancellationToken ct, T1 first, T2 second, T3 third) => action(ct, first, second, third, last)); }
CurryFirst <T1, T2, T3>(this ActionAsync <T1, T2, T3> action, T1 first) { return((CancellationToken ct, T2 second, T3 last) => action(ct, first, second, last)); }
CurryLast <T1, T2>(this ActionAsync <T1, T2> action, T2 last) { return((CancellationToken ct, T1 first) => action(ct, first, last)); }
Curry <T>(this ActionAsync <T> action, T value) { return((CancellationToken ct) => action(ct, value)); }
public Task ForEachAsync(ActionAsync <D> action) { return(_privateList.ForEachAsync(action)); }
public static ActionAsync <T> CreateAsync <T>(ActionAsync <T> action) { return(action); }
public Task ForConditionalItemsAsync(Predicate <D> match, ActionAsync <D> action) { return(_privateList.ForConditionalItemsAsync(match, action)); }
public QueueItem(ActionAsync <AsyncTestRunner> method) { _method = method; }
public LambdaCommandAsync(ActionAsync execute, Func <bool> canExecute = null) : this(async p => await execute(), canExecute is null ? (Func <object, bool>)null : p => canExecute())
public AsyncWeakEventHandler(ActionAsync callback) { _method = callback.GetMethodInfo(); _targetReference = new WeakReference(callback.Target, true); }