0

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?

  • Also see [How to chain and share prior results with promises](http://stackoverflow.com/questions/28714298/how-to-chain-and-share-prior-results-with-promises/28714863#28714863). – jfriend00 Oct 17 '16 at 22:24
  • You might like to check [How do I access previous promise results in a .then() chain?](http://stackoverflow.com/questions/28250680/how-do-i-access-previous-promise-results-in-a-then-chain) – Redu Oct 17 '16 at 22:24
  • Thank you. It was very helpful. – Adriano dos Santos Fernandes Oct 17 '16 at 23:27

0 Answers0