Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Created December 11, 2017 09:43
Show Gist options
  • Save jooyunghan/81c1af21897d77f93630f04fb89c6e44 to your computer and use it in GitHub Desktop.
Save jooyunghan/81c1af21897d77f93630f04fb89c6e44 to your computer and use it in GitHub Desktop.
function success() {
run(showToast("pass"));
}
function* showToast(message) {
var div = document.createElement("div");
div.className = "toast in";
div.textContent = message;
document.body.appendChild(div);
yield delay(1000);
div.className = "toast out";
yield delay(500);
document.body.removeChild(div);
}
function run(g) {
const { value, done } = g.next();
if (!done) {
value.then(() => run(g));
}
}
function delay(ms) {
return new Promise(r => setTimeout(r, ms));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment