public static int Start(string name, string description = null, ProgressOptions options = ProgressOptions.None, int parentId = -1) { // Automatically set C# progress as managed so they gets canceled when a domain reload occurs. if ((options & ProgressOptions.Unmanaged) == 0) { options |= ProgressOptions.Managed; } return(Internal_Start(name, description, options, parentId)); }
public async Task GeneralExecutionTest() { bool executed = false; void Nothing() { } Task NothingAsync() => Task.CompletedTask; void Execute() => executed = true; Task ExecuteAsync() { executed = true; return(Task.CompletedTask); } int[] choice = { Normal, Async }; IEnumerable <IEnumerable <int> > options = choice.Select(x => new[] { x }); ProgressOptions progressOptions = ops => Generator.GenerateOptions(ops, choice); ProgressSequence progressSequence = (gwts, option, _, isLast) => { switch (option) { case Normal: gwts = isLast ? gwts.SelectMany(x => Generator.GenerateCalls(x, Execute)) : gwts.SelectMany(x => Generator.GenerateCalls(x, Nothing)); break; case Async: gwts = isLast ? gwts.SelectMany(x => Generator.GenerateCalls(x, ExecuteAsync)) : gwts.SelectMany(x => Generator.GenerateCalls(x, NothingAsync)); break; } return(gwts); }; ExecuteCheck executeCheck = async seq => { executed = false; var cont = seq(); if (cont is IAsyncContinuation asyncCont) { await asyncCont; } executed.Should().BeTrue(); }; await Test(options, progressOptions, progressSequence, executeCheck); }
public async Task Test(IEnumerable <IEnumerable <int> > initialOptions, ProgressOptions progressOptions, ProgressSequence progressSequence, ExecuteCheck executeCheck) { var options = initialOptions; for (int level = 0; level < 7; level += 1) { var ops = options.Select(x => x.ToArray()).ToList(); foreach (var option in ops) { Func <GivenWhenThen> start = () => this; await TestSequence(start, level, option, progressSequence, executeCheck); } options = progressOptions(ops); } }
public async Task SequentialExecutionTest() { List <int> numbers = new List <int>(); Action DoCount(int x) => () => numbers.Add(x); AsyncAction DoCountAsync(int x) => () => { numbers.Add(x); return(Task.CompletedTask); }; var choice = new[] { Count, CountAsync }; var options = choice.Select(x => new[] { x }); ProgressOptions progressOptions = ops => Generator.GenerateOptions(ops, choice); ProgressSequence progressSequence = (gwts, option, i, _) => { switch (option) { case Count: gwts = gwts.SelectMany(x => Generator.GenerateCalls(x, DoCount(i))); break; case CountAsync: gwts = gwts.SelectMany(x => Generator.GenerateCalls(x, DoCountAsync(i))); break; } return(gwts); }; ExecuteCheck executeCheck = async seq => { numbers.Clear(); var cont = seq(); if (cont is IAsyncContinuation asyncCont) { await asyncCont; } numbers.Should().BeInAscendingOrder(); }; await Test(options, progressOptions, progressSequence, executeCheck); }
private static extern int Internal_Start(string name, string description, ProgressOptions options, int parentId);
public static int RunTask(string name, string description, Func <int, object, IEnumerator> taskHandler, ProgressOptions options = ProgressOptions.None, int parentId = -1, object userData = null) { var progressId = Start(name, description, options, parentId); s_Tasks.Add(new ProgressTask { id = progressId, handler = taskHandler, userData = userData, iterators = new Stack <IEnumerator>() }); EditorApplication.update -= RunTasks; EditorApplication.update += RunTasks; return(progressId); }