DataStoreCursor.close()

This API is available on Firefox OS for internal applications only.

The close() method of the DataStoreCursor interface makes a request to terminate the cursor.

Note: The Data Store API is available in Web Workers, from Firefox 32 onwards (Firefox OS 2.0; see bug 949325.)

Syntax

JavaScript
cursor.close();

Returns

Void.

Example

In the following example, we run DataStore.sync() to create a DataStoreCursor object allowing us to loop through any additions since the code last accessed the data store and update the data display as necessary.

The cursor is passed to the runNextTask() function, which calls DataStoreCursor.next to start the process of managing the next task — the resulting DataStoreTask object is passed to the manageTask() function to work out what to do with it. runNextTask() is then called repeatedly by manageTask() until the cursor has finished working through all the records. If an operation of type clear is found, cursor.close() is called to close the cursor.

JavaScript
var cursor = stores[0].sync();
runNextTask(cursor);

function runNextTask(cursor) {
 cursor.next().then(function(task) {
   manageTask(cursor, task);
 });
}

function manageTask(cursor, task) {
  if (task.operation == 'done') {
    // Finished adding contacts!
    return;
  }

  if (task.operation == 'add') {
    // Add the contacts that are different to how it was before
    displayExisting(task.id, task.data);
  }

  if (task.operation == 'clear') {
    // If one of the changes deletes the entire data store's contents,
    // then close the cursor
    cursor.close();
  }

  runNextTask(cursor);
}

Specifications

Specification Status Comment
Data Store API
The definition of 'close()' in that specification.
Draft  

The discussion concerning this API's creation happened in various Mozilla mailing lists and other places. A summary of the discussion and further pointers can be found on the Mozilla Wiki. For further feedback and questions, send mail to the dev-webapi mailing list.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support No support No support No support No support No support
Feature Android Chrome Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support No support No support No support 1.0.1 No support No support No support
Available in web workers No support No support No support 2.0 No support No support No support

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/datastorecursor/close

API close Data Store Data Store API Database DataStoreCursor Method Reference Référence Storage storage