diff options
| author | William Boman <william@redwill.se> | 2022-04-13 15:51:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-13 15:51:42 +0200 |
| commit | ee082883d18a8990cec359862db4e93ea850cb8c (patch) | |
| tree | 843aa37a9ec3d19b48ebb45ecf1f43407133c948 /tests/core/async | |
| parent | run autogen_metadata.lua (diff) | |
| download | mason-ee082883d18a8990cec359862db4e93ea850cb8c.tar mason-ee082883d18a8990cec359862db4e93ea850cb8c.tar.gz mason-ee082883d18a8990cec359862db4e93ea850cb8c.tar.bz2 mason-ee082883d18a8990cec359862db4e93ea850cb8c.tar.lz mason-ee082883d18a8990cec359862db4e93ea850cb8c.tar.xz mason-ee082883d18a8990cec359862db4e93ea850cb8c.tar.zst mason-ee082883d18a8990cec359862db4e93ea850cb8c.zip | |
feat(async): add a.wait_all (#596)
Diffstat (limited to 'tests/core/async')
| -rw-r--r-- | tests/core/async/async_spec.lua | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/tests/core/async/async_spec.lua b/tests/core/async/async_spec.lua index 3eacd145..9795adce 100644 --- a/tests/core/async/async_spec.lua +++ b/tests/core/async/async_spec.lua @@ -121,12 +121,37 @@ describe("async", function() end) ) - it("should not accept yielding non-promise values", function() - local err = assert.has_error(function() + it("should accept yielding non-promise values to parent coroutine context", function() + local thread = coroutine.create(function(val) a.run_blocking(function() - coroutine.yield(1) + coroutine.yield(val) end) end) - assert.equals("Expected Promise to have been yielded in async coroutine.", err) + local ok, value = coroutine.resume(thread, 1337) + assert.is_true(ok) + assert.equals(1337, value) end) + + it( + "should run all suspending functions concurrently", + async_test(function() + local start = timestamp() + local function sleep(ms) + return function() + a.sleep(ms) + end + end + a.wait_all { + sleep(100), + sleep(100), + sleep(100), + sleep(100), + sleep(100), + } + local grace = 50 + local delta = timestamp() - start + assert.is_true(delta <= (100 + grace)) + assert.is_true(delta >= (100 - grace)) + end) + ) end) |
