No .fail without .then?
pwuertz opened this issue · 3 comments
pwuertz commented
In contrast to the QPromise::reject
promise that is being tested in tst_fail
, regular non-void promises fail to compile .fail
methods being attached directly to p
:
auto p = QPromise<int>([&](
const QPromiseResolve<int>& resolve,
const QPromiseReject<int>& reject)
{
resolve(42);
reject(43);
});
p.fail([](int x) {
Q_UNUSED(x);
});
...qtpromise/src/qtpromise/qpromise_p.h:604: error: no matching function for call to ‘QtPromisePrivate::PromiseData<int>::resolve()’
promise->m_d->resolve();
^~~~~~~
If .fail
is preceded by a dummy .then
method, the fail works:
p.then([](){}).fail([](int x) {
Q_UNUSED(x);
});
simonbrunel commented
simonbrunel commented
Actually, fail()
is supposed to recover an error and thus must return the "replacement" value required to continue the promise chain:
auto p = QPromise<int>([&](auto resolve, auto reject) {
reject(43);
});
p.fail([](int x) {
Q_UNUSED(x);
return -1;
});
pwuertz commented
Oh, that makes sense. So just a misunderstanding on my part, thanks for clearing that up.
If I happen to find a good spot for a static_assert with a fitting message for such a mistake I'll let you know.