mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
util.promise: all()/all_settled() pass through non-promise values
This commit is contained in:
parent
2141d9d94a
commit
fec0d44e89
2 changed files with 63 additions and 22 deletions
|
@ -369,6 +369,21 @@ describe("util.promise", function ()
|
|||
assert.spy(cb).was_called(1);
|
||||
assert.same({ [true] = "nope", [false] = "yep" }, result);
|
||||
end);
|
||||
it("passes through non-promise values", function ()
|
||||
local r1;
|
||||
local p1 = promise.new(function (resolve) r1 = resolve end);
|
||||
local p = promise.all({ [true] = p1, [false] = "yep" });
|
||||
|
||||
local result;
|
||||
local cb = spy.new(function (v)
|
||||
result = v;
|
||||
end);
|
||||
p:next(cb);
|
||||
assert.spy(cb).was_called(0);
|
||||
r1("nope");
|
||||
assert.spy(cb).was_called(1);
|
||||
assert.same({ [true] = "nope", [false] = "yep" }, result);
|
||||
end);
|
||||
end);
|
||||
describe("all_settled()", function ()
|
||||
it("works with fulfilled promises", function ()
|
||||
|
@ -443,6 +458,24 @@ describe("util.promise", function ()
|
|||
bar = { status = "fulfilled", value = "yep" };
|
||||
}, result);
|
||||
end);
|
||||
it("passes through non-promise values", function ()
|
||||
local r1;
|
||||
local p1 = promise.new(function (resolve) r1 = resolve end);
|
||||
local p = promise.all_settled({ foo = p1, bar = "yep" });
|
||||
|
||||
local result;
|
||||
local cb = spy.new(function (v)
|
||||
result = v;
|
||||
end);
|
||||
p:next(cb);
|
||||
assert.spy(cb).was_called(0);
|
||||
r1("nope");
|
||||
assert.spy(cb).was_called(1);
|
||||
assert.same({
|
||||
foo = { status = "fulfilled", value = "nope" };
|
||||
bar = "yep";
|
||||
}, result);
|
||||
end);
|
||||
end);
|
||||
describe("catch()", function ()
|
||||
it("works", function ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue