Skip to content

Instantly share code, notes, and snippets.

@simsong
Last active November 25, 2019 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simsong/331b9313fa885473e6efb89610a05c5a to your computer and use it in GitHub Desktop.
Save simsong/331b9313fa885473e6efb89610a05c5a to your computer and use it in GitHub Desktop.
promise example
function getDataFromAPI(data, options) {
fetch("/app/get_stats")
.then(function (response) {
return response.json();
})
.then(function (result) {
var sysload_dict = result.sysload;
Object.keys(sysload_dict).forEach(function (key) {
data.addRow([key,
sysload_dict[key]['freeGB'],
sysload_dict[key]['min1'],
sysload_dict[key]['min5'],
sysload_dict[key]['min15']
])
});
drawTable(data, options);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment