--- layout: docs title: TaskQueue edit_url: "https://github.com/nylas/N1/blob/master/src/flux/stores/task-queue.coffee" ---
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.
if @_thread && @_thread.unread
Actions.queueTask(new ChangeStarredTask(thread: @_thread, starred: true))
Actions.dequeueMatchingTask({
type: 'FileUploadTask',
matching: {
filePath: uploadData.filePath
}
})
Support for creating custom Task subclasses in third-party packages is coming soon. This is currently blocked by the ActionBridge, which is responsible for sending actions between windows, since it's JSON serializer is not extensible.
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"} |
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. |