Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for returned Promises reliably #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/datastore-method-utils/help-run-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var _ = require('@sailshq/lodash');
var flaverr = require('flaverr');
var helpLeaseConnection = require('./help-lease-connection');
var STRIP_COMMENTS_RX = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg;
var isPromise = require('is-promise');


/**
Expand Down Expand Up @@ -105,7 +106,7 @@ module.exports = function helpRunTransaction(options, done){
});//_∏_ </ invoked `during` >

// Take care of unhandled promise rejections from `await` (if appropriate)
if (options.during.constructor.name === 'AsyncFunction') {
if (isPromise(promiseOrResultMaybe)) {
if (!seemsToExpectCallback) {
promiseOrResultMaybe = promiseOrResultMaybe.then(function(resultMaybe){
didDuringFnAlreadyHalt = true;
Expand Down
3 changes: 2 additions & 1 deletion lib/datastore-method-utils/private/do-with-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var assert = require('assert');
var _ = require('@sailshq/lodash');
var flaverr = require('flaverr');
var STRIP_COMMENTS_RX = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg;
var isPromise = require('is-promise');


/**
Expand Down Expand Up @@ -115,7 +116,7 @@ module.exports = function doWithConnection(options, done){
});//_∏_ </ invoked `during` >

// Take care of unhandled promise rejections from `await` (if appropriate)
if (options.during.constructor.name === 'AsyncFunction') {
if (isPromise(promiseOrResultMaybe)) {
if (!seemsToExpectCallback) {
promiseOrResultMaybe = promiseOrResultMaybe.then(function(resultMaybe){
didDuringFnAlreadyHalt = true;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"async": "2.0.1",
"chalk": "1.1.3",
"flaverr": "^1.8.0",
"is-promise": "^4.0.0",
"parley": "^3.3.2",
"prompt": "0.2.14",
"sails-disk": "^2.0.0",
Expand Down