Trying to write a small chrome extension that relies on callback request functions in the chrome.* Interface, I quickly landed on promises and async / await, since I needed to guarantee the order of certain operations, trying to avoid the callback hell .
However, as soon as I introduced async / await into some functions, each function that used them also had to be turned into an async function in order for await to be able to return a value. In the end, even some global constants became promises, for example.
const DEBUG = new Promise(function(resolve){ chrome.management.getSelf(resolve); }).then(function(self){ return self.installType == 'development'; });
However, now I need to write await everywhere, and the appearance of strange errors, such as if(DEBUG){...} , is always done too simply.
While it seems that you can identify errors with ESLINT , the await entry everywhere seems unnecessarily cumbersome, and so I was wondering if , if Javascript has some better construction, what am I missing?
(Subjectively, my current use of await / async seems to be reversed, promises are stored as is, unless explicitly expected, but it seems to me more desirable that promises wait by default in async functions and only be saved as naked promises when explicitly requested.)
javascript asynchronous async-await
kdb
source share