From b48a2409e74c7396ab1fcaf81f7ca17881612857 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 22 Mar 2018 07:46:23 +0000 Subject: util.async: Add ready() to check whether running in async context --- spec/util_async_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/util_async_spec.lua') diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua index 58d54487..ac71e755 100644 --- a/spec/util_async_spec.lua +++ b/spec/util_async_spec.lua @@ -579,4 +579,18 @@ describe("util.async", function() assert.spy(r.watchers.ready).was_not.called(); end); end); + + describe("#ready()", function () + it("should return false outside an async context", function () + assert.falsy(async.ready()); + end); + it("should return true inside an async context", function () + local r = new(function () + assert.truthy(async.ready()); + end); + r:run(true); + assert.spy(r.func).was.called(); + assert.spy(r.watchers.error).was_not.called(); + end); + end); end); -- cgit v1.2.3