Skip to content

Commit

Permalink
refactor(repository): simplify ensurePromise helper
Browse files Browse the repository at this point in the history
loopback-datasource-juggler is always using native Promises,
no need to wrap the promises returned by juggler APIs into another
Promise instance.

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
  • Loading branch information
bajtos committed Jun 14, 2019
1 parent 7ea2ad6 commit ba3f389
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/repository/src/repositories/legacy-juggler-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Getter, isPromiseLike} from '@loopback/context';
import {Getter} from '@loopback/context';
import * as assert from 'assert';
import * as legacy from 'loopback-datasource-juggler';
import {
Expand Down Expand Up @@ -74,11 +74,8 @@ export function bindModel<T extends juggler.ModelBaseClass>(
* @param p - Promise or void
*/
export function ensurePromise<T>(p: legacy.PromiseOrVoid<T>): Promise<T> {
if (p && isPromiseLike(p)) {
// Juggler uses promise-like Bluebird instead of native Promise
// implementation. We need to convert the promise returned by juggler
// methods to proper native Promise instance.
return Promise.resolve(p);
if (p && p instanceof Promise) {
return p;
} else {
return Promise.reject(new Error('The value should be a Promise: ' + p));
}
Expand Down

0 comments on commit ba3f389

Please sign in to comment.