/// <summary> /// /// </summary> /// <param name="func"></param> /// <param name="checkpoint"></param> /// <param name="priority"></param> /// <returns></returns> public static async Task <Guid> EnqueueAsync(Func <Task <object> > func, Func <Task <bool> > checkpoint, Priority priority = Priority.High) { if (Interlocked.CompareExchange(ref isInitiated, 0, 0) == 1) { var referencedTask = new ReferencedFunc <object> { guid = Guid.NewGuid(), func = func, checkpoint = checkpoint }; GetQueue((int)priority).Enqueue(referencedTask); if (Interlocked.CompareExchange(ref isProcessing, 0, 0) == 0) { await StartProcessing(); } return(referencedTask.guid); } else { throw new InvalidOperationException("Service has not been Initiated."); } }
private static void EnqueueReferencedFunc(ReferencedFunc <object> referencedTask) { GetQueue(referencedTask.priority).Enqueue(referencedTask); }
private static async Task ExecuteAsync(ReferencedFunc <object> referencedTask) { await(referencedTask?.func?.Invoke()); }