Use Promise.coroutine() instead of Zotero.spawn() for saveItems()

(Use -w for diff)
This commit is contained in:
Dan Stillman 2016-02-02 05:30:05 -05:00
parent a6caa14412
commit e8046d8ad2

View File

@ -81,11 +81,10 @@ Zotero.Translate.ItemSaver.prototype = {
* save progress. The callback will be called as attachmentCallback(attachment, false, error) * save progress. The callback will be called as attachmentCallback(attachment, false, error)
* on failure or attachmentCallback(attachment, progressPercent) periodically during saving. * on failure or attachmentCallback(attachment, progressPercent) periodically during saving.
*/ */
"saveItems":function(items, callback, attachmentCallback) { "saveItems": Zotero.Promise.coroutine(function* (items, callback, attachmentCallback) {
Zotero.spawn(function* () {
try { try {
let newItems = [], standaloneAttachments = []; let newItems = [], standaloneAttachments = [];
yield (Zotero.DB.executeTransaction(function* () { yield Zotero.DB.executeTransaction(function* () {
for (let iitem=0; iitem<items.length; iitem++) { for (let iitem=0; iitem<items.length; iitem++) {
let item = items[iitem], newItem, myID; let item = items[iitem], newItem, myID;
// Type defaults to "webpage" // Type defaults to "webpage"
@ -145,7 +144,7 @@ Zotero.Translate.ItemSaver.prototype = {
// add to new item list // add to new item list
newItems.push(newItem); newItems.push(newItem);
} }
}.bind(this))); }.bind(this));
// Handle standalone attachments outside of the transaction // Handle standalone attachments outside of the transaction
for (let iitem of standaloneAttachments) { for (let iitem of standaloneAttachments) {
@ -157,8 +156,7 @@ Zotero.Translate.ItemSaver.prototype = {
} catch(e) { } catch(e) {
callback(false, e); callback(false, e);
} }
}, this); }),
},
"saveCollections": Zotero.Promise.coroutine(function* (collections) { "saveCollections": Zotero.Promise.coroutine(function* (collections) {
var collectionsToProcess = collections.slice(); var collectionsToProcess = collections.slice();