--- layout: docs title: Task edit_url: "https://github.com/nylas/N1/blob/master/src/flux/tasks/task.coffee" ---
Tasks represent individual changes to the datastore that alter the local cache and need to be synced back to the server.
To create a new task, subclass Task and implement the following methods:
Task.Status.Finished
or Task.Status.Retry
. Rejections are considered
exception cases and are logged to our server.
Returning Task.Status.Retry
will cause the TaskQueue
to leave your task
on the queue and run it again later. You should only return Task.Status.Retry
if your task encountered a transient error (for example, a 0
but not a 400
).performRemote
is called at the right time, subclasses should implement
shouldWaitForTask(other)
. For example, the SendDraft
task is dependent
on the draft's files' UploadFile
tasks completing.Tasks may also implement shouldDequeueOtherTask(other)
. Returning true
will cause the other event to be removed from the queue. This is useful in
offline mode especially, when the user might Save
,Save
,Save
,Save
,Send
.
Each newly queued Save
can cancel the (unstarted) save task in the queue.
Tasks that need to support undo/redo should implement canBeUndone
, isUndo
,
createUndoTask
, and createIdenticalTask
.