Update to use homebridge types
This commit is contained in:
@ -1,30 +1,32 @@
|
||||
|
||||
/**
|
||||
* Helper function to convert callbacks into promises
|
||||
* @param func
|
||||
* @param func
|
||||
*/
|
||||
export default function callbackify(func: (...args: any[]) => Promise<any>): Function {
|
||||
return (...args: any[]) => {
|
||||
const onlyArgs: any[] = [];
|
||||
let maybeCallback: Function | null = null;
|
||||
|
||||
for (const arg of args) {
|
||||
if (typeof arg === 'function') {
|
||||
maybeCallback = arg;
|
||||
break;
|
||||
}
|
||||
export default function callbackify(
|
||||
func: (...args: any[]) => Promise<any>
|
||||
): Function {
|
||||
return (...args: any[]) => {
|
||||
const onlyArgs: any[] = [];
|
||||
let maybeCallback: Function | null = null;
|
||||
|
||||
onlyArgs.push(arg);
|
||||
}
|
||||
for (const arg of args) {
|
||||
if (typeof arg === "function") {
|
||||
maybeCallback = arg;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!maybeCallback) {
|
||||
throw new Error("Missing callback parameter!");
|
||||
}
|
||||
|
||||
const callback = maybeCallback;
|
||||
|
||||
func(...onlyArgs)
|
||||
.then((data: any) => callback(null, data))
|
||||
.catch((err: any) => callback(err))
|
||||
onlyArgs.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!maybeCallback) {
|
||||
throw new Error("Missing callback parameter!");
|
||||
}
|
||||
|
||||
const callback = maybeCallback;
|
||||
|
||||
func(...onlyArgs)
|
||||
.then((data: any) => callback(null, data))
|
||||
.catch((err: any) => callback(err));
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user