Promise.resolve().then vs setImmediate vs nextTick

Using Promise.resolve().then has no advantages over nextTick. It runs on the same queue, but have slightly higher priority, that is, promise handler can prevent next tick callback from ever running, the opposite is not possible. This behaviour is an implementation detail and should not be relied on. Promise.resolve().then is obviously slower (a lot, I think), … Read more

When is the body of a Promise constructor callback executed?

Immediately, yes, by specification. From the MDN: The executor function is executed immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise constructor even returns the created object) This is defined in the ECMAScript specification (of course, it’s harder to read…) here (StepĀ 9 as of this edit, showing … Read more

Why is the response object from JavaScript fetch API a promise?

If your question is “why does response.json() return a promise?” then @Bergi provides the clue in comments: “it waits for the body to load”. If your question is “why isn’t response.json an attribute?”, then that would have required fetch to delay returning its response until the body had loaded, which might be OK for some, … Read more

Why does the Promise constructor require a function that calls ‘resolve’ when complete, but ‘then’ does not – it returns a value instead?

Bergi’s answer is excellent, and has been very helpful to me. This answer is complementary to his. In order to visualize the relationship between the Promise() constructor and the then() method, I created this diagram. I hope it helps somebody… maybe even me, a few months months from now. The main idea here is that … Read more

Why doesn’t the code after await run right away? Isn’t it supposed to be non-blocking?

Just as its name implies, the await keyword will cause the function to “wait” until the corresponding promise resolves before executing the next line. The whole point of await is to provide a way to wait for an asynchronous operation to complete before continuing. The difference between this and blocking code is that the world … Read more

Problems inherent to jQuery $.Deferred (jQuery 1.x/2.x)

Update: jQuery 3.0 has fixed the problems outlined below. It is truly Promises/A+ compliant. Yes, jQuery promises have serious and inherent problems. That said, since the article was written jQuery made significant efforts to be more Promises/Aplus complaint and they now have a .then method that chains. So even in jQuery returnsPromise().then(a).then(b) for promise returning … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)