I try to change a “function f(input).then(function(output) …) in a form like : “output = await something”
I’m deal with the (tsayen)dom-to-image library … (in the brwser, not with nodes.js)
I must deal with multiple DOMelement
So, I wish to could make : dataUrl = await F(HTMLElement)
with the definition of the librairy, I should script something like :
domtoimage.toPng(HTMLElement1).then(function(dataUrl1){ {do with dataUrl1} domtoimage.toPng(HTMLElement2).then(function(dataUrl2){ (do with dataUrl2} domtoimage.toPng(HTMLElement3).then ... etc ...
I DON’T know how much HTMLElements I have to deal with …
So, I wish “dataurl = await someasyncfunction(HTMLElement)” in order to be able to script a loop …
I’ve tried :
async function dom2url(HtmlElem) { (resolve,reject) => { domtoimage.toPng(this.HtmlElem).then(async function(dataUrl){ return await dataUrl; })}; }
then
dataUrl = await dom2url(htmlElem) but don't match
I’ve read so many times “async / await”, “Promises” and “Arrow function” that my head is full ! Please : could you help me ? not to give me somes references to these functions, of course 🙂
