summaryrefslogtreecommitdiff
path: root/src/mbgl/util/thread.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-09-03 13:28:55 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-08 16:36:47 -0700
commit030234c7a6c7f6c5a901dab68591c9cfb2d4828f (patch)
tree669e831aecdd9cd74173cb93088b13979887e81e /src/mbgl/util/thread.hpp
parente4995e8d3a38dfd2ed64337e712ecf701af37454 (diff)
downloadqtlocation-mapboxgl-030234c7a6c7f6c5a901dab68591c9cfb2d4828f.tar.gz
[core] Rework invokeWithCallback so that the callback is last
Diffstat (limited to 'src/mbgl/util/thread.hpp')
-rw-r--r--src/mbgl/util/thread.hpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp
index 31a56a4834..91eef745fa 100644
--- a/src/mbgl/util/thread.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -30,20 +30,23 @@ public:
Thread(const ThreadContext&, Args&&... args);
~Thread();
- // Invoke object->fn(args...) in the runloop thread.
+ // Invoke object->fn(args...) asynchronously.
template <typename Fn, class... Args>
void invoke(Fn fn, Args&&... args) {
loop->invoke(bind(fn), std::forward<Args>(args)...);
}
- // Invoke object->fn(args...) in the runloop thread, then invoke callback(result) in the current thread.
- template <typename Fn, class Cb, class... Args>
+ // Invoke object->fn(args...) asynchronously. The final argument to fn must be a callback.
+ // The provided callback is wrapped such that it is invoked, in the current thread (which
+ // must have a RunLoop), once for each time the invocation of fn invokes the wrapper, each
+ // time forwarding the passed arguments, until such time as the AsyncRequest is cancelled.
+ template <typename Fn, class... Args>
std::unique_ptr<AsyncRequest>
- invokeWithCallback(Fn fn, Cb&& callback, Args&&... args) {
- return loop->invokeWithCallback(bind(fn), callback, std::forward<Args>(args)...);
+ invokeWithCallback(Fn fn, Args&&... args) {
+ return loop->invokeWithCallback(bind(fn), std::forward<Args>(args)...);
}
- // Invoke object->fn(args...) in the runloop thread, and wait for the result.
+ // Invoke object->fn(args...) asynchronously, but wait for the result.
template <typename Fn, class... Args>
auto invokeSync(Fn fn, Args&&... args) {
using R = std::result_of_t<Fn(Object, Args&&...)>;