I wan't to return a promise to mocha (or anything else I would use promises) where in the last "then" I need an argument returned only in the first "then". This is how I did it:
it("#startTransaction()", () => {
let status = master.getStatus();
let filename = getTempFile("Attachment-startTransaction.fdb");
return dispatcher.createDatabase(status, filename)
.then((attachment) =>
attachment.startTransaction(status)
.then((transaction) => ({ attachment: attachment, transaction: transaction }))
)
.then((p) =>
p.transaction.commit(status)
.then(() => p.attachment)
)
.then((attachment) => attachment.dropDatabase(status))
.then(() => {
status.dispose();
})
.catch(() => {
assert(false);
});
});
So, after commit a transaction I need the attachment. Another way I could do is like done with "status", declaring it before the chain, but I don't like this way.
Can I make my promise code more readable?