summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--async/autotests/asynctest.cpp2
-rw-r--r--async/src/async.h11
2 files changed, 8 insertions, 5 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp
index c507721..61ab8bc 100644
--- a/async/autotests/asynctest.cpp
+++ b/async/autotests/asynctest.cpp
@@ -340,8 +340,6 @@ void AsyncTest::testSyncEach()
340 340
341void AsyncTest::testJoinedEach() 341void AsyncTest::testJoinedEach()
342{ 342{
343 QFAIL("Crashes due to bad lifetime of Future");
344
345 auto job1 = Async::start<QList<int>, int>( 343 auto job1 = Async::start<QList<int>, int>(
346 [](int v, Async::Future<QList<int>> &future) { 344 [](int v, Async::Future<QList<int>> &future) {
347 new AsyncSimulator<QList<int>>(future, { v * 2 }); 345 new AsyncSimulator<QList<int>>(future, { v * 2 });
diff --git a/async/src/async.h b/async/src/async.h
index c6ca9e7..7425604 100644
--- a/async/src/async.h
+++ b/async/src/async.h
@@ -499,9 +499,14 @@ private:
499 auto job = otherJob; 499 auto job = otherJob;
500 FutureWatcher<OutOther> *watcher = new FutureWatcher<OutOther>(); 500 FutureWatcher<OutOther> *watcher = new FutureWatcher<OutOther>();
501 QObject::connect(watcher, &FutureWatcherBase::futureReady, 501 QObject::connect(watcher, &FutureWatcherBase::futureReady,
502 [watcher, &future]() { 502 [watcher, future]() {
503 Async::detail::copyFutureValue(watcher->future(), future); 503 // FIXME: We pass future by value, because using reference causes the
504 future.setFinished(); 504 // future to get deleted before this lambda is invoked, leading to crash
505 // in copyFutureValue()
506 // copy by value is const
507 auto outFuture = future;
508 Async::detail::copyFutureValue(watcher->future(), outFuture);
509 outFuture.setFinished();
505 delete watcher; 510 delete watcher;
506 }); 511 });
507 watcher->setFuture(job.exec(in ...)); 512 watcher->setFuture(job.exec(in ...));