public async Task LazyLazy() { { var l = UniTask.Lazy(() => After()); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); var a2 = await a; var b2 = await b; var c2 = await c; (a2, b2, c2).Should().Be((10, 10, 10)); } { var l = UniTask.Lazy(() => AfterException()); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); await Assert.ThrowsAsync <TaskTestException>(async() => await a); await Assert.ThrowsAsync <TaskTestException>(async() => await b); await Assert.ThrowsAsync <TaskTestException>(async() => await c); } }
public async Task LazyImmediate() { { var l = UniTask.Lazy(() => UniTask.FromResult(1).AsUniTask()); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); await a; await b; await c; } { var l = UniTask.Lazy(() => UniTask.FromException(new TaskTestException())); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); await Assert.ThrowsAsync <TaskTestException>(async() => await a); await Assert.ThrowsAsync <TaskTestException>(async() => await b); await Assert.ThrowsAsync <TaskTestException>(async() => await c); } }
public async Task LazyLazy() { { var l = UniTask.Lazy(() => After()); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); await a; await b; await c; } { var l = UniTask.Lazy(() => AfterException()); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); await Assert.ThrowsAsync <TaskTestException>(async() => await a); await Assert.ThrowsAsync <TaskTestException>(async() => await b); await Assert.ThrowsAsync <TaskTestException>(async() => await c); } }
public async Task LazyImmediate() { { var l = UniTask.Lazy(() => UniTask.FromResult(1)); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); var a2 = await a; var b2 = await b; var c2 = await c; (a2, b2, c2).Should().Be((1, 1, 1)); } { var l = UniTask.Lazy(() => UniTask.FromException <int>(new TaskTestException())); var a = AwaitAwait(l.Task); var b = AwaitAwait(l.Task); var c = AwaitAwait(l.Task); await Assert.ThrowsAsync <TaskTestException>(async() => await a); await Assert.ThrowsAsync <TaskTestException>(async() => await b); await Assert.ThrowsAsync <TaskTestException>(async() => await c); } }
private async UniTaskVoid Start() { var array = new[] { UniTask.Lazy(() => SendMessageAsync(400, "400")), UniTask.Lazy(() => SendMessageAsync(200, "200")), UniTask.Lazy(() => SendMessageAsync(800, "800")) }; await array // UniTaskAsyncEnumerableに変換 .ToUniTaskAsyncEnumerable() .ForEachAwaitAsync(async x => { Debug.Log("await"); var s = await x; Debug.Log(s); }); Debug.Log("Done!"); }
private void Awake() { _asyncLazy = UniTask.Lazy(async() => await Resources.LoadAsync <Texture>("Textures/enemy") as Texture); }