Skip to content

Conversation

b-admike
Copy link
Contributor

Description

Add promise support to transaction class methods.

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@b-admike b-admike self-assigned this Jun 26, 2019
Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b-admike 👍 I left a suggestion regarding the test.

});
});

it('can return promise', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion (I am not confident to say it would be a better testing approach :p)

We can test a promise returned by calling those chain methods like .then(), see example in juggler https://github.com/strongloop/loopback-datasource-juggler/blob/de4718d5b81d29ac23597172d8ee591617924fe0/test/transaction.test.js#L94

@b-admike b-admike force-pushed the chore/promisify-transaction-methods branch from 7b8d7f4 to f63ff39 Compare June 26, 2019 19:15
*/
Transaction.prototype.commit = function(cb) {
cb = cb || createPromiseCallback();
return this.connector.commit(this.connection, cb);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to return cb.promise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @raymondfeng 🙇 that is correct.

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start!

@b-admike b-admike force-pushed the chore/promisify-transaction-methods branch 2 times, most recently from 069d9a8 to 494b260 Compare June 28, 2019 13:18
};

return expect(
Transaction.begin(connectorObject, '')).to.eventually.be.instanceOf(Transaction);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are usually using slightly different formatting.

LB3 style:

return expect(Transaction.begin(connectorObject, ''))
  .to.eventually.be.instanceOf(Transaction);

LB4 style (?)

return expect(
  Transaction.begin(connectorObject, '')
).to.eventually.be.instanceOf(Transaction);

Copy link
Contributor Author

@b-admike b-admike Jun 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'll go with LB3 (EDIT LB4) style 👍

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please get @raymondfeng's approval before landing.

Add promise support to transaction methods.

Co-Authored-By: Miroslav Bajtoš <mbajtoss@gmail.com>
@b-admike b-admike force-pushed the chore/promisify-transaction-methods branch from 494b260 to d79092a Compare June 28, 2019 13:27
@b-admike
Copy link
Contributor Author

I've looked at the failed builds, and none of them seem related to changes in this PR. Will merge as is.

@b-admike b-admike merged commit b8aeb23 into master Jun 28, 2019
@b-admike b-admike deleted the chore/promisify-transaction-methods branch June 28, 2019 15:59
@bajtos bajtos changed the title chore: add promise support chore: add promise support to Transaction methods Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants