diff options
author | Dan Vrátil <dvratil@redhat.com> | 2014-12-12 13:24:42 +0100 |
---|---|---|
committer | Dan Vrátil <dvratil@redhat.com> | 2014-12-12 13:24:45 +0100 |
commit | d799ec65afc3746873ab4cb48c2e22e931252ea1 (patch) | |
tree | c81ab78462b88a64654753ef56ac69d69715780c /async/src | |
parent | 5b8b8e4e0471ea904388b3b9c8efd597f9daebea (diff) | |
download | sink-d799ec65afc3746873ab4cb48c2e22e931252ea1.tar.gz sink-d799ec65afc3746873ab4cb48c2e22e931252ea1.zip |
Async: add some simple documentation
Diffstat (limited to 'async/src')
-rw-r--r-- | async/src/async.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/async/src/async.h b/async/src/async.h index 66e455c..a10b3e8 100644 --- a/async/src/async.h +++ b/async/src/async.h | |||
@@ -119,6 +119,18 @@ public: | |||
119 | 119 | ||
120 | } // namespace Private | 120 | } // namespace Private |
121 | 121 | ||
122 | /** | ||
123 | * Start an asynchronous job sequence. | ||
124 | * | ||
125 | * Async::start() is your starting point to build a chain of jobs to be executed | ||
126 | * asynchronously. | ||
127 | * | ||
128 | * @param func An asynchronous function to be executed. The function must have | ||
129 | * void return type, and accept exactly one argument of type @p Async::Future<In>, | ||
130 | * where @p In is type of the result. | ||
131 | */ | ||
132 | template<typename Out> | ||
133 | Job<Out> start(ThenTask<Out> func); | ||
122 | 134 | ||
123 | class JobBase | 135 | class JobBase |
124 | { | 136 | { |
@@ -135,6 +147,48 @@ protected: | |||
135 | Private::ExecutorBase *mExecutor; | 147 | Private::ExecutorBase *mExecutor; |
136 | }; | 148 | }; |
137 | 149 | ||
150 | /** | ||
151 | * An Asynchronous job | ||
152 | * | ||
153 | * A single instance of Job represents a single method that will be executed | ||
154 | * asynchrously. The Job is started by @p Job::exec(), which returns @p Async::Future | ||
155 | * immediatelly. The Future will be set to finished state once the asynchronous | ||
156 | * task has finished. You can use @p Async::Future::waitForFinished() to wait for | ||
157 | * for the Future in blocking manner. | ||
158 | * | ||
159 | * It is possible to chain multiple Jobs one after another in different fashion | ||
160 | * (sequential, parallel, etc.). Calling Job::exec() will then return a pending | ||
161 | * @p Async::Future, and will execute the entire chain of jobs. | ||
162 | * | ||
163 | * @code | ||
164 | * auto job = Job::start<QList<int>>( | ||
165 | * [](Async::Future<QList<int>> &future) { | ||
166 | * MyREST::PendingUsers *pu = MyREST::requestListOfUsers(); | ||
167 | * QObject::connect(pu, &PendingOperation::finished, | ||
168 | * [&](PendingOperation *pu) { | ||
169 | * future->setValue(dynamic_cast<MyREST::PendingUsers*>(pu)->userIds()); | ||
170 | * future->setFinished(); | ||
171 | * }); | ||
172 | * }) | ||
173 | * .each<QList<MyREST::User>, int>( | ||
174 | * [](const int &userId, Async::Future<QList<MyREST::User>> &future) { | ||
175 | * MyREST::PendingUser *pu = MyREST::requestUserDetails(userId); | ||
176 | * QObject::connect(pu, &PendingOperation::finished, | ||
177 | * [&](PendingOperation *pu) { | ||
178 | * future->setValue(Qlist<MyREST::User>() << dynamic_cast<MyREST::PendingUser*>(pu)->user()); | ||
179 | * future->setFinished(); | ||
180 | * }); | ||
181 | * }); | ||
182 | * | ||
183 | * Async::Future<QList<MyREST::User>> usersFuture = job.exec(); | ||
184 | * usersFuture.waitForFinished(); | ||
185 | * QList<MyRest::User> users = usersFuture.value(); | ||
186 | * @endcode | ||
187 | * | ||
188 | * In the example above, calling @p job.exec() will first invoke the first job, | ||
189 | * which will retrieve a list of IDs, and then will invoke the second function | ||
190 | * for each single entry in the list returned by the first function. | ||
191 | */ | ||
138 | template<typename Out, typename ... In> | 192 | template<typename Out, typename ... In> |
139 | class Job : public JobBase | 193 | class Job : public JobBase |
140 | { | 194 | { |