42 void FuturesTest::testSequencer ()
50 .Then ([&loop, &res] (
int cnt)
58 QCoreApplication::processEvents ();
63 void FuturesTest::testHeterogeneousTypes ()
69 bool executed =
false;
71 [] (int) {
return MakeReadyFuture<Bar> ({}); } >>
72 [] (Bar) {
return MakeReadyFuture<Baz> ({}); } >>
73 [&executed, &loop] (Baz)
81 QCoreApplication::processEvents ();
83 QCOMPARE (executed,
true);
86 void FuturesTest::testDestruction ()
89 bool executed =
false;
94 [&executed, &loop] (int)
101 QTimer::singleShot (100, &loop, SLOT (quit ()));
105 QCoreApplication::processEvents ();
107 QCOMPARE (executed,
false);
110 void FuturesTest::testDestructionHandler ()
112 const auto finished = 1;
113 const auto destructed = 2;
116 bool executed =
false;
123 .DestructionValue ([] {
return destructed; }) >>
127 [&executed, &value, &loop] (
int val)
134 QTimer::singleShot (10, &loop, SLOT (quit ()));
138 QCoreApplication::processEvents ();
140 QCOMPARE (executed,
true);
141 QCOMPARE (value, destructed);
144 void FuturesTest::testNoDestrHandler ()
150 bool executed =
false;
152 .DestructionValue ([&executed] { executed =
true; }) >>
153 [] (
int) {
return MakeReadyFuture<Bar> ({}); } >>
154 [] (Bar) {
return MakeReadyFuture<Baz> ({}); } >>
155 [&loop] (Baz) { loop.quit (); };
159 QCoreApplication::processEvents ();
161 QCOMPARE (executed,
false);
164 void FuturesTest::testNoDestrHandlerSetBuildable ()
166 const auto finished = 1;
169 bool executed =
false;
175 [&executed, &value, &loop] (
int val)
184 QCoreApplication::processEvents ();
186 QCOMPARE (executed,
true);
187 QCOMPARE (value, finished);
190 void FuturesTest::testMulti ()
199 .MultipleResults ([&] (
int sub)
204 [&] { loop.quit (); });
206 iface.reportStarted ();
207 iface.setProgressRange (0, 2);
208 iface.reportResult (1, 0);
209 iface.reportResult (2, 1);
210 iface.reportResult (3, 2);
211 iface.reportFinished ();
215 QCoreApplication::processEvents ();
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.