Unsettled API - A context for thread-safe execution of work. More...
#include <work_queue.hpp>
Public Member Functions | |
| work_queue () | |
| Unsettled API - Create a work queue. | |
| work_queue (container &) | |
| Unsettled API - Create a work queue backed by a container. | |
| bool | add (work fn) |
| Unsettled API - Add work fn to the work queue. | |
| bool | add (void_function0 &fn) |
| Deprecated - Use add(work). | |
| void | schedule (duration, work fn) |
| Unsettled API - Add work fn to the work queue after a duration. | |
| void | schedule (duration, void_function0 &fn) |
| Deprecated - Use schedule(duration, work). | |
Unsettled API - A context for thread-safe execution of work.
Event-handler functions associated with a single proton::connection are called in sequence. The connection's proton::work_queue allows you to "inject" extra work from any thread and have it executed in the same sequence in the serialized context of the connection. That is the event loop / driver thread that runs that connection's callbacks not on the calling thread.
You may also create arbitrary proton::work_queue objects backed by a container that allow other objects to have their own serialized work queues that can have work injected safely from other threads. The container ensures that the work is correctly serialized and run on a thread that is running the container.
The proton::work class represents the work to be queued and can be created from a function that takes no parameters and returns no value.
| bool add | ( | work | fn | ) |
Unsettled API - Add work fn to the work queue.
Work fn will be called serially with other work in the queue. The work will be deferred and executed on the connection thread associated with the owner of the work queue. It will be executed serially with any callbacks associated with that connection.
If the work queue is backed by a container, the work will be executed on a thread that is running the container, but there are no guarantees about how it will be serialized with any connection callbacks in that container.
| void schedule | ( | duration | , |
| work | fn ) |
Unsettled API - Add work fn to the work queue after a duration.
Scheduled execution is "best effort". It may not be possible to inject the work after the elapsed duration. There will be no indication of this.
Work fn will be called serially with other work in the queue. The work will be deferred and executed on the connection thread associated with the owner of the work queue. It will be executed serially with any callbacks associated with that connection.
If the work queue is backed by a container, the work will be executed on a thread that is running the container, but there are no guarantees about how it will be serialized with any connection callbacks in that container.