49 return QtConcurrent::run ([msecs]
51 std::this_thread::sleep_for (std::chrono::milliseconds (msecs));
58 void FuturesTest::testSequencer ()
66 .Then ([&loop, &res] (
int cnt)
77 void FuturesTest::testHeterogeneousTypes ()
83 bool executed =
false;
84 Sequence (
nullptr, MkWaiter () (50)) >>
85 [] (int) {
return MakeReadyFuture<Bar> ({}); } >>
86 [] (Bar) {
return MakeReadyFuture<Baz> ({}); } >>
87 [&executed, &loop] (Baz)
95 QCOMPARE (executed,
true);
98 void FuturesTest::testDestruction ()
101 bool executed =
false;
106 [&executed, &loop] (int)
113 QTimer::singleShot (100, &loop, SLOT (quit ()));
117 QCOMPARE (executed,
false);
120 void FuturesTest::testDestructionHandler ()
122 const auto finished = 1;
123 const auto destructed = 2;
126 bool executed =
false;
132 future =
Sequence (&obj, MkWaiter () (100))
133 .DestructionValue ([destructed] {
return destructed; }) >>
137 [&executed, &value, &loop] (
int val)
144 QTimer::singleShot (10, &loop, SLOT (quit ()));
148 QCOMPARE (executed,
true);
149 QCOMPARE (value, destructed);
152 void FuturesTest::testNoDestrHandler ()
158 bool executed =
false;
159 Sequence (
nullptr, MkWaiter () (50))
160 .DestructionValue ([&executed] { executed =
true; }) >>
161 [] (
int) {
return MakeReadyFuture<Bar> ({}); } >>
162 [] (Bar) {
return MakeReadyFuture<Baz> ({}); } >>
163 [&loop] (Baz) { loop.quit (); };
167 QCOMPARE (executed,
false);
170 void FuturesTest::testNoDestrHandlerSetBuildable ()
172 const auto finished = 1;
175 bool executed =
false;
181 [&executed, &value, &loop] (
int val)
190 QCOMPARE (executed,
true);
191 QCOMPARE (value, finished);
QFuture< T > MakeReadyFuture(const T &t)
Creates a ready future holding the given value.
detail::SequenceProxy< detail::SequencerRetType_t< QFuture< T > >, QFuture< T >, detail::EmptyDestructionTag > Sequence(QObject *parent, const QFuture< T > &future)
Creates a sequencer that allows chaining multiple futures.