Skip to content

Instantly share code, notes, and snippets.

@AlexGilleran
Created August 28, 2017 06:39
Show Gist options
  • Save AlexGilleran/0d1e149aeb76bd4435d5419b6131f3a9 to your computer and use it in GitHub Desktop.
Save AlexGilleran/0d1e149aeb76bd4435d5419b6131f3a9 to your computer and use it in GitHub Desktop.
Wait for a job to be deleted by godaddy/kubernetes-client as a promise
function waitForDelete() {
return new Promise((resolve, reject) => {
const stream = batchApi.ns.jobs.getStream({ qs: { watch: true } });
const jsonStream = new JSONStream();
stream.pipe(jsonStream);
const onError = (error: Error) => reject(error);
const onData = (res: any) => {
if (res.type === "DELETED") {
jsonStream.removeListener("error", onError);
jsonStream.removeListener("data", onData);
stream.destroy();
resolve();
}
};
jsonStream.on("error", onError);
jsonStream.on("data", onData);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment