mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
create all docs before calling back
Resolves #423. Also changes the callback signature, invoking it with the error and docs, rather than the error, totalCreated, and docs. The third paramter isn't used, and the second parameter should be an array. (Since totalCreated was 0 on callback, it was falsy and replaced with an empty array when used in format_entries.)
This commit is contained in:
+14
-12
@@ -96,21 +96,23 @@ function storage(name, storage, pushover) {
|
||||
|
||||
// store new documents using the storage mechanism
|
||||
function create (docs, fn) {
|
||||
with_collection(function(err, collection) {
|
||||
if (err) { fn(err); return; }
|
||||
// potentially a batch insert
|
||||
var firstErr = null,
|
||||
totalCreated = 0;
|
||||
with_collection(function(err, collection) {
|
||||
if (err) { fn(err); return; }
|
||||
// potentially a batch insert
|
||||
var firstErr = null,
|
||||
numDocs = docs.length,
|
||||
totalCreated = 0;
|
||||
|
||||
docs.forEach(function(doc) {
|
||||
collection.update(doc, doc, {upsert: true}, function (err, created) {
|
||||
firstErr = firstErr || err;
|
||||
totalCreated += created;
|
||||
});
|
||||
sendPushover(doc);
|
||||
docs.forEach(function(doc) {
|
||||
collection.update(doc, doc, {upsert: true}, function (err, created) {
|
||||
firstErr = firstErr || err;
|
||||
if (++totalCreated === numDocs) {
|
||||
fn(firstErr, docs);
|
||||
}
|
||||
});
|
||||
fn(firstErr, totalCreated, docs);
|
||||
sendPushover(doc);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//currently the Android upload will send the last MBG over and over, make sure we get a single notification
|
||||
|
||||
Reference in New Issue
Block a user