public GenericAsyncUrl2Url(string url, int maxInvoer = 1) { Url = new Uri(url); InnerInvoker = new AsyncInvoker <KeyValuePair <string, int> >(maxInvoer); InnerInvoker.InvokerAction = ParseUrl; }
public GenericAsyncUrl2Url(string url, int maxInvoer = 1) { Url = new Uri(url); InnerInvoker = new AsyncInvoker<KeyValuePair<string, int>>(maxInvoer); InnerInvoker.InvokerAction = ParseUrl; }
public ZhihuAnswerUrl2Url(string name, int maxInvoker = 1) { Url = new Uri(@"http://www.zhihu.com/people/" + name + @"/answers"); InnerInvoker = new AsyncInvoker <string>(maxInvoker); InnerInvoker.InvokerAction = InvokerProc; }
public ZhihuAnswerUrl2Url(string name, int maxInvoker = 1) { Url = new Uri(@"http://www.zhihu.com/people/" + name + @"/answers"); InnerInvoker = new AsyncInvoker<string>(maxInvoker); InnerInvoker.InvokerAction = InvokerProc; }
public void AsyncInvokerLimitTimeTest() { AsyncInvoker asyncInvoker = new AsyncInvoker(); Thread.Sleep(1500); Assert.AreEqual(1, asyncInvoker.Output.Count); Assert.AreEqual("method", asyncInvoker.Output[0]); }
public void AsyncInvokerTest() { AsyncInvoker asyncInvoker = new AsyncInvoker(); Thread.Sleep(3000); Assert.AreEqual <string>("method", asyncInvoker.Output[0]); Assert.AreEqual <string>("fast", asyncInvoker.Output[1]); Assert.AreEqual <string>("slow", asyncInvoker.Output[2]); }
public void AsyncInvokerNotEnoughTimeTest() { AsyncInvoker asyncInvoker = new AsyncInvoker(); Thread.Sleep(2200); Assert.AreEqual(2, asyncInvoker.Output.Count); Assert.AreEqual("method", asyncInvoker.Output[0]); Assert.AreEqual("fast", asyncInvoker.Output[1]); }
public void AsyncInvokerTwoTimeTest() { AsyncInvoker asyncInvoker = new AsyncInvoker(); Thread.Sleep(5500); Assert.AreEqual(5, asyncInvoker.Output.Count); Assert.AreEqual("method", asyncInvoker.Output[0]); Assert.AreEqual("fast", asyncInvoker.Output[1]); Assert.AreEqual("slow", asyncInvoker.Output[2]); Assert.AreEqual("fast", asyncInvoker.Output[3]); Assert.AreEqual("slow", asyncInvoker.Output[4]); }
public async Task SimpleChainTestAsync() { async Task AddAsync(int n, AsyncInvoker <int, int> chain, CancellationToken ct) { chain.State += n; await chain.InvokeAsync(ct); } (await AsyncInvoker.New(new int[0], 0, AddAsync).RunAsync()).State .Should().Be(0); (await AsyncInvoker.New(new [] { 10 }, 1, AddAsync).RunAsync()).State .Should().Be(11); (await AsyncInvoker.New(new [] { 1, 2, 3 }, 0, AddAsync).RunAsync()).State .Should().Be(6); }
public async Task StatelessChainTestAsync() { async Task IncrementAsync(Box <int> box, AsyncInvoker <Box <int>, Unit> chain, CancellationToken ct) { box.Value += 1; await Task.Yield(); await chain.InvokeAsync(ct).ConfigureAwait(false); } // It's important to have fairly long chain here: // the calls are async-recursive, so in this case // they shouldn't trigger StackOverflowException // even for very long chains const int chainLength = 1000; var boxes = Enumerable.Range(0, chainLength).Select(i => Box.New(0)).ToArray(); await AsyncInvoker.New(boxes, IncrementAsync).RunAsync(); boxes.Sum(b => b.Value).Should().Be(chainLength); }
public UserColorUrl2Url(int maxInvoker = 1) { InnerInvoker = new AsyncInvoker<string>(maxInvoker); InnerInvoker.InvokerAction = InvokerProc; }
public async Task OrderAndErrorHandlingTestAsync() { async Task Concat1Async(string s, AsyncInvoker <string, string> invoker, CancellationToken cancellationToken) { if (s == "e") { throw new ArgumentException(); } invoker.State += s; await invoker.InvokeAsync(cancellationToken); } async Task Concat2Async(string s, AsyncInvoker <string, string> invoker, CancellationToken cancellationToken) { await Task.Yield(); if (s == "e") { throw new ArgumentException(); } invoker.State += s; } (await AsyncInvoker.New(new [] { "a", "b" }, "", Concat1Async).RunAsync()) .State.Should().Be("ab"); (await AsyncInvoker.New(new [] { "a", "b" }, "", Concat1Async, InvocationOrder.Reverse).RunAsync()) .State.Should().Be("ba"); (await AsyncInvoker.New(new [] { "a", "b" }, "", Concat2Async).RunAsync()) .State.Should().Be("ab"); (await AsyncInvoker.New(new [] { "a", "b" }, "", Concat2Async, InvocationOrder.Reverse).RunAsync()) .State.Should().Be("ba"); Action action; action = () => AsyncInvoker.New(new [] { "a", "e" }, "", Concat1Async) .RunAsync().Result.Ignore(); action.Should().Throw <ArgumentException>(); action = () => AsyncInvoker.New(new [] { "a", "e" }, "", Concat1Async, InvocationOrder.Reverse) .RunAsync().Result.Ignore(); action.Should().Throw <ArgumentException>(); action = () => AsyncInvoker.New(new [] { "a", "e" }, "", Concat2Async) .RunAsync().Result.Ignore(); action.Should().Throw <ArgumentException>(); action = () => AsyncInvoker.New(new [] { "a", "e" }, "", Concat2Async, InvocationOrder.Reverse) .RunAsync().Result.Ignore(); action.Should().Throw <ArgumentException>(); var errorHandlerCalled = false; void ErrorHandler(Exception e, string s, AsyncInvoker <string, string> invoker) => errorHandlerCalled = true; action = () => { errorHandlerCalled = false; AsyncInvoker.New(new[] { "a", "e" }, "", Concat1Async, InvocationOrder.Straight, ErrorHandler) .RunAsync().Result.Ignore(); errorHandlerCalled.Should().BeTrue(); }; action.Should().NotThrow(); action = () => { errorHandlerCalled = false; AsyncInvoker.New(new[] { "a", "e" }, "", Concat1Async, InvocationOrder.Reverse, ErrorHandler) .RunAsync().Result.Ignore(); errorHandlerCalled.Should().BeTrue(); }; action.Should().NotThrow(); }
public UserColorUrl2Url(int maxInvoker = 1) { InnerInvoker = new AsyncInvoker <string>(maxInvoker); InnerInvoker.InvokerAction = InvokerProc; }
public AsyncUrl2ResultRunner(int maxInvoker = 1) { InnerInvoker = new AsyncInvoker <string>(maxInvoker); InnerInvoker.InvokerAction = str => ToResult?.OnNewUrl(str); }
public Collect2Items(int maxInvoker = 1) { InnerInvoker = new AsyncInvoker <string>(maxInvoker); InnerInvoker.InvokerAction = InvokerProc; }
public MultiUrlGeneraterRunner(int threadCount = 1) { InnerInvoker = new AsyncInvoker <string>(threadCount); InnerInvoker.InvokerAction = Method; }
public MultiUrlGeneraterRunner(int threadCount = 1) { InnerInvoker = new AsyncInvoker<string>(threadCount); InnerInvoker.InvokerAction = Method; }
public AsyncUrl2ResultRunner(int maxInvoker = 1) { InnerInvoker = new AsyncInvoker<string>(maxInvoker); InnerInvoker.InvokerAction = str => ToResult?.OnNewUrl(str); }
public Item2Image(int maxInvoker = 1) { InnerInvoker = new AsyncInvoker <string>(maxInvoker); InnerInvoker.InvokerAction = InvokerProc; }