-
-
Save getify/6ac8e321d0ea50d7d55f8491304f5693 to your computer and use it in GitHub Desktop.
quick sketch of CAF
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
btn.addEventListener("send-btn",onSend); | |
send = CAF(send); | |
var prevSend = Promise.resolve(); | |
function onSend(evt) { | |
prevSend.finally(function f(){ | |
prevSend = send( | |
CAF.timeout(1000,"send took too long."), | |
{ some: "data" } | |
) | |
.catch(console.log); | |
}); | |
} | |
function *send(signal,data){ | |
var res = yield fetch("/some/url",{ | |
body: JSON.stringify(data), | |
signal | |
}); | |
if (res.ok) { | |
let resp = yield res.text(); // note: this call doesn't need a Promise.race() because CAF does it for you | |
console.log(resp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment