mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
43 lines
2.3 KiB
HTML
43 lines
2.3 KiB
HTML
---
|
|
layout: docs
|
|
title: Task
|
|
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/tasks/task.coffee"
|
|
---
|
|
|
|
<h2>Summary</h2>
|
|
|
|
<div class="markdown-from-sourecode">
|
|
<p><p>Tasks represent individual changes to the datastore that
|
|
alter the local cache and need to be synced back to the server.</p>
|
|
<p>To create a new task, subclass Task and implement the following methods:</p>
|
|
<ul>
|
|
<li>performLocal:
|
|
Return a <a href='https://github.com/petkaantonov/bluebird/blob/master/API.md'>Promise</a> that does work immediately. Must resolve or the task
|
|
will be thrown out. Generally, you should optimistically update
|
|
the local cache here.</li>
|
|
<li>performRemote:
|
|
Do work that requires dependencies to have resolved and may need to be
|
|
tried multiple times to succeed in case of network issues.
|
|
performRemote must return a <a href='https://github.com/petkaantonov/bluebird/blob/master/API.md'>Promise</a>, and it should always resolve with
|
|
<code>Task.Status.Finished</code> or <code>Task.Status.Retry</code>. Rejections are considered
|
|
exception cases and are logged to our server.
|
|
Returning <code>Task.Status.Retry</code> will cause the <code>TaskQueue</code> to leave your task
|
|
on the queue and run it again later. You should only return <code>Task.Status.Retry</code>
|
|
if your task encountered a transient error (for example, a <code>0</code> but not a <code>400</code>).</li>
|
|
<li>shouldWaitForTask:
|
|
Tasks may be arbitrarily dependent on other tasks. To ensure that
|
|
<code>performRemote</code> is called at the right time, subclasses should implement
|
|
<code>shouldWaitForTask(other)</code>. For example, the <code>SendDraft</code> task is dependent
|
|
on the draft's files' <code>UploadFile</code> tasks completing.</li>
|
|
</ul>
|
|
<p>Tasks may also implement <code>shouldDequeueOtherTask(other)</code>. Returning true
|
|
will cause the other event to be removed from the queue. This is useful in
|
|
offline mode especially, when the user might <code>Save</code>,<code>Save</code>,<code>Save</code>,<code>Save</code>,<code>Send</code>.
|
|
Each newly queued <code>Save</code> can cancel the (unstarted) save task in the queue.</p>
|
|
<p>Tasks that need to support undo/redo should implement <code>canBeUndone</code>, <code>isUndo</code>,
|
|
<code>createUndoTask</code>, and <code>createIdenticalTask</code>.</p>
|
|
</p>
|
|
</div>
|
|
|
|
<ul>
|
|
</ul>
|