Version: Smart Feature Phone 2.5

DataStoreCursor.close()

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

Syntax#

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.

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);
}