Created
August 28, 2017 06:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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