2014-09-17 01:49:25 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var contacts = (function() {
|
2014-09-19 22:26:51 +04:00
|
|
|
function forEach(callback) {
|
2014-10-15 12:12:15 +04:00
|
|
|
var sender = DumbPipe.open("contacts", {}, function(message) {
|
2014-10-13 09:36:22 +04:00
|
|
|
if (message) {
|
|
|
|
callback(message);
|
2014-10-15 12:12:15 +04:00
|
|
|
} else {
|
|
|
|
DumbPipe.close(sender);
|
2014-09-19 23:58:56 +04:00
|
|
|
}
|
2014-10-13 09:36:22 +04:00
|
|
|
});
|
2014-09-17 01:49:25 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 21:06:57 +03:00
|
|
|
function getAll(callback) {
|
|
|
|
var contacts = [];
|
|
|
|
var sender = DumbPipe.open("contacts", {}, function(contact) {
|
|
|
|
if (!contact) {
|
|
|
|
callback(contacts);
|
|
|
|
DumbPipe.close(sender);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
contacts.push(contact);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var requestHandler = null;
|
|
|
|
function getNext(callback) {
|
|
|
|
if (requestHandler) {
|
|
|
|
callback(requestHandler());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAll(function(contacts) {
|
|
|
|
var idx = -1;
|
|
|
|
|
|
|
|
requestHandler = function() {
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
if (idx < contacts.length) {
|
|
|
|
return contacts[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
requestHandler = null;
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(requestHandler());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-17 01:49:25 +04:00
|
|
|
return {
|
2014-09-19 22:26:51 +04:00
|
|
|
forEach: forEach,
|
2014-11-06 21:06:57 +03:00
|
|
|
getNext: getNext,
|
2014-09-17 01:49:25 +04:00
|
|
|
};
|
|
|
|
})();
|