Skip to content

Commit 1d9979f

Browse files
bajtosraymondfeng
authored andcommitted
fixup! change ctx.getValueOrPromise to return ValueOrPromise
1 parent 24b217d commit 1d9979f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/context/src/context.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {ResolutionOptions, ResolutionSession} from './resolution-session';
1010
import {v1 as uuidv1} from 'uuid';
1111

1212
import * as debugModule from 'debug';
13+
import {ValueOrPromise} from '.';
1314
const debug = debugModule('loopback:context');
1415

1516
/**
@@ -408,12 +409,7 @@ export class Context {
408409
getValueOrPromise<T>(
409410
keyWithPath: string,
410411
optionsOrSession?: ResolutionOptions | ResolutionSession,
411-
): T | PromiseLike<T> | undefined {
412-
// ^^^ Note that boundValue can be any Promise-like implementation,
413-
// not necessarily the native Promise instance. As such, it may be
414-
// missing newer APIs like Promise#catch() and cannot be casted
415-
// directly to a Promise. Callers of this method should use
416-
// Promise.resolve() to convert the result into a native Promise.
412+
): ValueOrPromise<T | undefined> {
417413
const {key, path} = Binding.parseKeyWithPath(keyWithPath);
418414

419415
// backwards compatibility

packages/context/src/value-promise.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ export type BoundValue = any;
2121
/**
2222
* Representing a value or promise. This type is used to represent results of
2323
* synchronous/asynchronous resolution of values.
24+
*
25+
* Note that we are using PromiseLike instead of native Promise to describe
26+
* the asynchronous variant. This allows producers of async values to use
27+
* any Promise implementation (e.g. Bluebird) instead of native Promises
28+
* provided by JavaScript runtime.
2429
*/
25-
export type ValueOrPromise<T> = T | Promise<T>;
30+
export type ValueOrPromise<T> = T | PromiseLike<T>;
2631

2732
export type MapObject<T> = {[name: string]: T};
2833

0 commit comments

Comments
 (0)