Tengo un código como este.
async function doAsync(count){ //external function I need to use count++; console.log("async count is "+ count ); return await count; } function makeSyncChain(i){ //my chain that I could change i=doAsync(i); return i; } let val=0; console.log("sync count is " + makeSyncChain(val));La solución correcta debe ser:
async function doAsync(count){ //external function I need to use count++; console.log("async count is "+ count ); return await count; } let val=0; console.log("sync count is " + (await doAsync(val)));Pero en una clave incorrecta se puede escribir como (y sí , no funcionará , simplemente bloqueará el navegador ):
async function doAsync(count){ //external function I need to use count++; console.log("async count is "+ count ); return await count; } function makeSyncChain(i){ //my chain that I could change let isDone = false; let result; doAsync(i).then(r => { result = r; }).finally(() => { isDone = true; }); while (!isDone); return result; } let val=0; console.log("sync count is " + makeSyncChain(val));