diff options
author | eldritch horrors <pennae@lix.systems> | 2024-04-27 01:02:22 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-05-07 14:35:20 +0000 |
commit | 964ac8b0e88fb5789b87e33273e42363958d0afb (patch) | |
tree | a205072edf06b023d82e77d06f3e463c5169fc4b /tests/unit/libutil/closure.cc | |
parent | 230860dbb8fc061fd55b98cedd134cdc5097ea69 (diff) |
libutil: de-callback-ify computeClosure
only two users of this function exist. only one used it in a way that
even bears resemblance to asynchronicity, and even that one didn't do
it right. fully async and parallel computation would have only worked
if any getEdgesAsync never calls the continuation it receives itself,
only from more derived callbacks running on other threads. calling it
directly would cause the decoupling promise to be awaited immediately
*on the original thread*, completely negating all nice async effects.
Change-Id: I0aa640950cf327533a32dee410105efdabb448df
Diffstat (limited to 'tests/unit/libutil/closure.cc')
-rw-r--r-- | tests/unit/libutil/closure.cc | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/tests/unit/libutil/closure.cc b/tests/unit/libutil/closure.cc index 7597e7807..b4eaad6f9 100644 --- a/tests/unit/libutil/closure.cc +++ b/tests/unit/libutil/closure.cc @@ -16,15 +16,11 @@ map<string, set<string>> testGraph = { }; TEST(closure, correctClosure) { - set<string> aClosure; set<string> expectedClosure = {"A", "B", "C", "F", "G"}; - computeClosure<string>( + set<string> aClosure = computeClosure<string>( {"A"}, - aClosure, - [&](const string currentNode, function<void(promise<set<string>> &)> processEdges) { - promise<set<string>> promisedNodes; - promisedNodes.set_value(testGraph[currentNode]); - processEdges(promisedNodes); + [&](const string currentNode) { + return testGraph[currentNode]; } ); @@ -33,12 +29,10 @@ TEST(closure, correctClosure) { TEST(closure, properlyHandlesDirectExceptions) { struct TestExn {}; - set<string> aClosure; EXPECT_THROW( computeClosure<string>( {"A"}, - aClosure, - [&](const string currentNode, function<void(promise<set<string>> &)> processEdges) { + [&](const string currentNode) -> set<string> { throw TestExn(); } ), @@ -46,25 +40,4 @@ TEST(closure, properlyHandlesDirectExceptions) { ); } -TEST(closure, properlyHandlesExceptionsInPromise) { - struct TestExn {}; - set<string> aClosure; - EXPECT_THROW( - computeClosure<string>( - {"A"}, - aClosure, - [&](const string currentNode, function<void(promise<set<string>> &)> processEdges) { - promise<set<string>> promise; - try { - throw TestExn(); - } catch (...) { - promise.set_exception(std::current_exception()); - } - processEdges(promise); - } - ), - TestExn - ); -} - } |