2021年2月6日星期六

How to wait until a callback is finished to return from ES6 Proxy

I can't use promises because it force the user to convert everything to async functions for sync methods. Is there any way to force the proxy to not to return until the callback complete?

function callbackCase() {      function saySomething(callback) {          callback("Stackoverflow");      }        console.error = new Proxy(console.error, {          apply: (target, thisArg, args) => {              saySomething((result) => {                  return result;              })          }      })        let test = console.error();        console.log("From Callback Case", test);  }          function nonCallbackCase() {      console.errors = new Proxy(console.error, {          apply: (target, thisArg, args) => {              return "Stackoverflow";          }      })        let test = console.errors();        console.log("From Non Callback Case", test);  }      callbackCase()  nonCallbackCase()
https://stackoverflow.com/questions/66083897/how-to-wait-until-a-callback-is-finished-to-return-from-es6-proxy February 07, 2021 at 10:04AM

没有评论:

发表评论