getJob(id: string): Promise<any> { const jobs = this.batchApi.ns(this.namespace).jobs(id); return promisify(jobs.get.bind(jobs))(); }
describe('promisify', () => { const cb = (err, info) => { } const cbTest = (cb) => { cb(null, 5); } it('should convert a function with a callback to a promise', async () => { const promisifiedCbTest = promisify(cbTest); const result = await promisifiedCbTest; expect(result).toBe(5); }); });
async getRatio(): Promise<number> { this.reset(); const size: any = await promisify(this.state.size.bind(this.state))(); const ratio: number = size.width / size.height; return ratio; }
async clearInput(): Promise<void> { const removeFile = promisify(fs.unlink.bind(fs)); await removeFile(this.inputPath); }
// Make req.login async app.use((req: LoadedRequest, res, next): void => { req.login = promisify(req.login); next(); });
getConnectorConfigMap(): Promise<any> { const configmaps = this.coreApi.ns(this.namespace).configmaps; return promisify(configmaps.get.bind(configmaps))({ name: "connector-config" }).then((result: any) => _(result.data) .mapKeys((value: any, key: string) => { return key.slice(0, key.length - 5); }) .mapValues((value: string) => JSON.parse(value)) .value() ); }
async clearOutput(): Promise<void> { const removeFile = promisify(fs.unlink.bind(fs)); const removeAllOutput = this.slides.map(({ path }) => removeFile(path)); await Promise.all(removeAllOutput); }
createService(body: any): Promise<any> { const services = this.coreApi.ns(this.namespace).services; return promisify(services.post.bind(services))({ body }); }
updateConnectorConfigMap(id: string, newConfig: any) { const configmaps = this.coreApi.ns(this.namespace).configmaps; return promisify(configmaps.patch.bind(configmaps))({ name: "connector-config", body: { data: { [`${id}.json`]: newConfig && JSON.stringify(newConfig, null, 2) } } }); }
deleteJob(id: string) { const jobs = this.batchApi.ns(this.namespace).jobs; return promisify(jobs.delete.bind(jobs))({ name: id, body: { kind: "DeleteOptions", apiVersion: "batch/v1", propagationPolicy: "Background" } }); }
deleteService(id: string) { const services = this.coreApi.ns(this.namespace).services(id); return promisify(services.delete.bind(services))(); }
createJob(body: any): Promise<any> { const jobs = this.batchApi.ns(this.namespace).jobs; return promisify(jobs.post.bind(jobs))({ body }); }
getJobStatus(id: string): Promise<any> { const jobs = this.batchApi.ns(this.namespace).jobs(id); return promisify(jobs.get.bind(jobs))({ name: `status` }); }
getJobs(): Promise<any> { const jobs = this.batchApi.ns(this.namespace).jobs; return promisify(jobs.get.bind(jobs))(); }