Class Task<T, P>

#include <Geode/utils/Task.hpp>
classTask<T, P>{ ... }

Tasks represent an asynchronous operation that will be finished at some unknown point in the future. Tasks can report their progress, and will end either through finishing into a value, or due to being cancelled. Tasks are designed to provide a thread-safe general purpose abstraction for dealing with any asynchronous operations. The Task class satisfies EventFilter and as such is listened to using the Geode events system; tasks may have multiple listeners, and even if a listener is attached after the Task has finished it will receive the finished value. Tasks are a very cheap and tiny struct that just have a reference to a task Handle; as such, Tasks may (and should) be copied around without worry. It should be noted that a Task never owns itself - the listener(s) of a Task are expected to hold an instance of the Task for as long as they intend to listen to it. Usually this is done via just setting the Task as the filter to an EventListener, as the EventListener manages the lifetime of its filter Task itself does not carry a notion of fallibility aside from cancellation; it is customary to use the Result type in Tasks that might finish to a failure value. Once a Task has finished or has been cancelled, it can no longer be revived

Template parameters

T

The type the Task will eventually finish to. This type must be move-constructible; though as there is no way to move the value out of the Task (because of potentially multiple listeners), one should ensure they can reasonably copy the value out in some form if they wish to gain ownership of it after the Task is finished

P

The type of the progress values the Task (may) post
Examples0
Public static methods3
staticgeode::Taskimmediate(
Tvalue
,)

Create a new Task that immediately finishes with the given value

Parameters

value

The value the Task shall be finished with

name

The name of the Task; used for debugging
staticgeode::Taskrun(,)

Create a new Task with a function that returns the finished value. See the class description for details about Tasks

Parameters

body

The body aka actual code of the Task. Note that this function MUST be synchronous - Task creates the thread for you!

name

The name of the Task; used for debugging
staticgeode::TaskrunWithCallback(,)

Create a Task using a body that may need to create additional threads within itself; for example due to using an external library that creates its own thread

Parameters

body

The body aka actual code of the Task. The body may call its provided finish callback *exactly once* - subsequent calls will always be ignored

name

The name of the Task; used for debugging
Public member functions19
geode::Task&operator=()
No description provided
geode::Task&operator=()
No description provided
booloperator==()const
No description provided
booloperator!=()const
No description provided
booloperator<()const
No description provided
booloperator<=()const
No description provided
booloperator>()const
No description provided
booloperator>=()const
No description provided
T*getFinishedValue()

Get the value this Task finished to, if the Task had finished, or null otherwise. Note that this is simply a mutable reference to the value - you may not move out of it!

voidcancel()

Cancel this Task. If this is a Task that owns other Task(s) (for example one created through Task::map) then that Task is cancelled as well. If this is undesirable, use shallowCancel() instead

voidshallowCancel()

If this is a Task that owns other Task(s) (for example created through Task::map or Task::all), then this method cancels only this Task and not any of the Task(s) it is built on top of. Ownership of the other Task(s) will be released, so if this is the only Task listening to them, they will still be destroyed due to a lack of listeners

boolisPending()const
No description provided
boolisFinished()const
No description provided
boolisCancelled()const
No description provided
boolisNull()const

Check if this Task doesn’t actually do anything (for instance it was default-constructed)

geode::ListenerResulthandle(,)
No description provided
geode::EventListenerPool*getPool()const
No description provided
voidsetListener()
No description provided
geode::EventListenerProtocol*getListener()const
No description provided
Fields0
Protected member functions0
Protected fields0