I'd like to write a readKey
function that's async
, and then await
each key being pressed in the browser.
I'd like to build this up into synchronous, normal-looking code that's all based on async
-await
.
So then I could write a readLine
function that does await readKey()
until the user hits [enter], and delete the last key if the user hits [back], etc.
And then I could write functions that await readLine()
, and write functions that call them, etc.
I just don't know how to bridge the gap between writing a document.onkeypress
handler... and putting the keys in that event into some async readKey
function that I'd write. In other languages, I could use other multi-threading primitives to get there, but I can't figure out how to in js. I was trying to figure out if there was some way to yield
the value, but I can't see how to do that, either.