// const bugtamer = require("@bugtamer/async-status/lib/async-status")
const bugtamer = require("@bugtamer/async-status")
function showStats(asyncStatus, message) {
console.log(message)
console.log(` - Attempts: ${asyncStatus.attempts}`)
console.log(` - successful: ${asyncStatus.successfulAttempts}`)
console.log(` - failed: ${asyncStatus.failedAttempts}`)
console.log(` - State:`)
console.log(` - idle: ${asyncStatus.isIdle}`)
console.log(` - ongoing: ${asyncStatus.isOngoing}`)
console.log(` - Outcome:`)
console.log(` - successful: ${asyncStatus.wasSuccessful}`)
console.log(` - failed: ${asyncStatus.wasFailed}`)
console.log(` - Time elapsed: ${asyncStatus.elapsedTime} ms`)
}
// Let's show where the Internation Space Station currently is.
console.log("Let's see where the ISS is with Node " + process.version);
// We can use any package from NPM since they are all built in.
var getJSON = require("async-get-json");
const status = new bugtamer.AsyncStatus();
showStats(status, 'new AsyncStatus()')
status.start()
showStats(status, 'start()')
const url = "http://api.open-notify.org/iss-now.json"; // change it to make it fail
try {
// And we can use ES7 async/await to pull the ISS's position from the open API.
var result = await getJSON(url);
status.end()
showStats(status, 'end()')
} catch (error) {
status.abort()
showStats(status, 'abort()')
}
if (!!result) {
// RunKit will automatically display the last statement and try to find its best representation:
result.iss_position;
}