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