TaskQueue

Summary

The TaskQueue is a Flux-compatible Store that manages a queue of {Task} objects. Each {Task} represents an individual API action, like sending a draft or marking a thread as "read". Tasks optimistically make changes to the app's local cache and encapsulate logic for performing changes on the server, rolling back in case of failure, and waiting on dependent tasks.

The TaskQueue is essential to offline mode in N1. It automatically pauses when the user's internet connection is unavailable and resumes when online.

The task queue is persisted to disk, ensuring that tasks are executed later, even if the user quits N1.

The TaskQueue is only available in the app's main window. Rather than directly queuing tasks, you should use the {Actions} to interact with the {TaskQueue}. Tasks queued from secondary windows are serialized and sent to the application's main window via IPC.

Queueing a Task

if @_thread && @_thread.unread
  Actions.queueTask(new ChangeStarredTask(thread: @_thread, starred: true))

Dequeueing a Task

Actions.dequeueMatchingTask({
  type: 'DestroyCategoryTask',
  matching: {
    categoryId: 'bla'
  }
})

Instance Methods

findTask(typematching)

Parameters

Argument Description
type The string name of the task class, or the Task class itself. (ie: {SaveDraftTask} or 'SaveDraftTask')
matching Optional An {Object} with criteria to pass to _.isMatch. For a SaveDraftTask, this could be {draftClientId: "123123"}

Returns

Return Values
Returns an existing task in the queue that matches the type you provide, and any other match properties. Useful for checking to see if something, like a "SendDraft" task is in-flight.
Returns a matching {Task}, or null.

results matching ""

    No results matching ""