2019-04-18 21:32:38 +00:00
|
|
|
// Copyright IBM Corp. 2015,2019. All Rights Reserved.
|
|
|
|
// Node module: loopback-connector
|
2016-10-19 10:55:35 +00:00
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2022-08-21 13:41:32 +00:00
|
|
|
type PromiseCallback = <T extends unknown>() => {
|
|
|
|
(err: unknown, data: T): void;
|
|
|
|
promise: Promise<T>;
|
|
|
|
};
|
2016-10-19 10:55:35 +00:00
|
|
|
|
2022-08-21 13:41:32 +00:00
|
|
|
export function createPromiseCallback(): PromiseCallback {
|
|
|
|
let cb: PromiseCallback;
|
2016-10-19 10:55:35 +00:00
|
|
|
|
2019-08-02 13:50:51 +00:00
|
|
|
const promise = new Promise(function(resolve, reject) {
|
2022-08-21 13:41:32 +00:00
|
|
|
// @ts-ignore
|
2016-10-19 10:55:35 +00:00
|
|
|
cb = function(err, data) {
|
|
|
|
if (err) return reject(err);
|
|
|
|
return resolve(data);
|
|
|
|
};
|
|
|
|
});
|
2022-08-21 13:41:32 +00:00
|
|
|
// @ts-ignore
|
2016-10-19 10:55:35 +00:00
|
|
|
cb.promise = promise;
|
2022-08-21 13:41:32 +00:00
|
|
|
// @ts-ignore
|
2016-10-19 10:55:35 +00:00
|
|
|
return cb;
|
|
|
|
}
|