abbr / deasync

Turns async function into sync via JavaScript wrapper of Node event loop
MIT License
971 stars 73 forks source link

how to get promise result #187

Open wideweide opened 10 months ago

wideweide commented 10 months ago

function SyncFunction(){ var ret; setTimeout(function(){
ret = "hello"; },3000);

// may be promise.then(res=>ret=res) while(ret === undefined) { require('deasync').sleep(100); } // returns hello with sleep; undefined without return ret;
}

// may be promise.then(res=>ret=res)? but it seems waste time to wait?

is there better method?