<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Eddy Bruel on Medium]]></title>
        <description><![CDATA[Stories by Eddy Bruel on Medium]]></description>
        <link>https://medium.com/@ejpbruel?source=rss-e27f1a78e27a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QFYvCbK5y9NhJss2.jpg</url>
            <title>Stories by Eddy Bruel on Medium</title>
            <link>https://medium.com/@ejpbruel?source=rss-e27f1a78e27a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 11:01:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ejpbruel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Break Your Promises, or Why Promises Are Not So Great]]></title>
            <link>https://medium.com/@ejpbruel/how-to-break-your-promises-or-why-promises-are-not-so-great-b6a68adc2163?source=rss-e27f1a78e27a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6a68adc2163</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Eddy Bruel]]></dc:creator>
            <pubDate>Mon, 07 Mar 2016 09:48:43 GMT</pubDate>
            <atom:updated>2016-03-07T09:48:43.200Z</atom:updated>
            <content:encoded><![CDATA[<p>A couple of weeks ago, I wrote the first in a series of two posts that I intended to write on promises. In <a href="https://medium.com/@ejpbruel/the-drawbacks-of-callbacks-or-why-promises-are-great-5dedf2c98c67#.ea7eqsphe">that post</a>, I talked about the kind of problems you run into when writing asynchronous code using callbacks. I then introduced promises, and showed how they make it much easier to write asynchronous code.</p><p>However, although promises make it much easier to write asynchronous code, they certainly don’t make it easier to write <em>correct</em> asynchronous code. Therefore, in the second part of the series (i.e. the post you’re reading right now!), I’d like to talk about some of the common mistakes people make when writing asynchronous code with promises.</p><p>This post is going to be a long one: I felt that some of these mistakes are not easy to grasp (they certainly weren’t for me) unless you have some understanding of how promises are supposed to work. I therefore opted to spend a few sections on diving into how the behavior of promises is specified. I hope these sections do more to clarify than they do to detract from the main story.</p><h4>Some Useful Helper Methods</h4><p>Before we begin, let’s introduce a few useful helper methods. These methods are part of the Promise API, and are also explained <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise">here</a>. We will use these methods in the examples throughout the rest of this post.</p><p>The <strong>Promise</strong> constructor has a helper method, <strong>resolve</strong>, which creates a promise that is immediately resolved with a given value:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d74af2ef59cd3d83719a3b3aecd8131/href">https://medium.com/media/9d74af2ef59cd3d83719a3b3aecd8131/href</a></iframe><p><strong>Promise </strong>also has another helper method, <strong>reject</strong>, which creates a promise that is immediately rejected with a given reason:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0f6a4d5781804f31a128dcbf81eda7f/href">https://medium.com/media/f0f6a4d5781804f31a128dcbf81eda7f/href</a></iframe><p>Since the fulfilled handler in the above example is never called, we can replace it with null:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d998cf24aa9864a00fb465d7dc7b0945/href">https://medium.com/media/d998cf24aa9864a00fb465d7dc7b0945/href</a></iframe><p>Instances of Promise have a helper method, <strong>catch</strong>, which is a shorthand for the above:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cc07219fbcb5791cea9ae2b720a3fcb/href">https://medium.com/media/2cc07219fbcb5791cea9ae2b720a3fcb/href</a></iframe><h4>Error Handling With Promises</h4><p>The first category of mistakes we will look into is related to error handling. This is one of the trickiest parts of promises to get right. Because promises are asynchronous, error handling works a little different from what you are used to in synchronous code. For this reason, before looking at how error handling can go wrong, let’s first take a look at how it is <em>supposed</em> to work:</p><p>Suppose you install a fulfilled handler, but not a reject handler, on a rejected promise. The resulting code will look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57756d5417e931c951fb300579807e03/href">https://medium.com/media/57756d5417e931c951fb300579807e03/href</a></iframe><p>Recall that when you call the <strong>then</strong> method on a promise, it returns another promise. If the original promise is rejected, and no reject handler is installed, the promise returned by the <strong>then</strong> method is rejected with the same reason as the original promise. Similarly, if the original promise is resolved, and a fulfilled handler is installed, but the call to this handler fails somehow, the promise returned by the <strong>then </strong>method is rejected with the exception thrown by the fulfilled handler..</p><p>One consequence of this is that when we chain multiple calls to the <strong>then</strong> method to define a sequence of operations, and one of the fulfilled handlers throws an exception, none of the subsequent fulfilled handlers will be executed:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1961e9fab9c1ba153b0ad82b274b54b6/href">https://medium.com/media/1961e9fab9c1ba153b0ad82b274b54b6/href</a></iframe><p>Note that this is similar to how exceptions behave in synchronous code. However, we don’t yet have a way to detect and recover from these exceptions in promise code. How can we accomplish this?</p><p>Recall that if the original promise is rejected, and a reject handler is installed, the promise returned by the <strong>then</strong> method is resolved with the value returned by the reject handler. This allows us to write code like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e6a7c7a8222990cc48b049764318d05/href">https://medium.com/media/7e6a7c7a8222990cc48b049764318d05/href</a></iframe><p>Note that we replaced one of the calls to the <strong>then</strong> method with a call to the <strong>catch </strong>method. Unlike the previous example, the final fulfilled handler is now called. but it is passed the value returned by the reject handler instead of the fulfilled handler.</p><p>To summarise: when we defining a sequence of operations with the <strong>then</strong> method, if one fulfilled handler throws an exception, none of the subsequent fulfilled handlers will be called, unless there is a reject handler somewhere in the sequence.</p><h4>Mistake 1: Forgetting to Install a Reject Handler</h4><p>In the previous section we took a quick look at how to do error handling with promises. In this section, we will look at some of the mistakes people make when writing error handling code.</p><p>One of the most common mistakes that people seem to make with promises is forgetting to install a reject handler. The reason this is so common is that errors are not always caught where they are thrown. This makes missing reject handlers hard to spot, as the following example illustrates:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/890861b7e3e14912cc16c3acbd6d717d/href">https://medium.com/media/890861b7e3e14912cc16c3acbd6d717d/href</a></iframe><p>If we only had knowledge about the function <strong>f</strong>, we might erroneously assume that we forgot to install a catch handler on the promise it returns, but since <strong>g</strong> installs a reject handler on the promise returned by <strong>f</strong> as well. However, this only remains true as long as <strong>g</strong> is the only consumer of <strong>f</strong>. It’s all too easy for someone else to add another consumer of <strong>f</strong> later on, and then forget to install a catch handler there, since they didn’t know how exactly <strong>f</strong> was implemented.</p><p>This problem is not unique to promise code. For the same reason, the same kind of mistakes are common in synchronous code as well: its all too easy to forget to catch an exception when we add a new consumer of a function.</p><p>The underlying problem is that exception handling breaks the principle of locality of reference (which means that you should be able to tell what a piece of code does without having to look at its surrounding context), and this makes it hard to write code that is correct.</p><p>There is, however, one big difference between exception handling in synchronous and promise code, and it’s a rather unfortunate one. With promises, the results of forgetting to install a reject handler are far more catastrophic:</p><p>When you forget to catch an exception in synchronous code, the exception will propagate up, until it reaches the top level of your code. If it is not caught there, it will cause your program to terminate with an error message.</p><p>In contrast, when you forget to install a reject handler in promise code, your code will fail silently: No exception will be thrown. No error will be logged. Your code will simply stop working for no apparent reason.</p><p>You might wonder why this is the case: can’t we simply throw an exception when a promise is rejected when it doesn’t have a reject handler installed? Unfortunately, the answer is no: because of their asynchronous nature, the promise may not be rejected until longer after we’ve returned from the function in which it was created (which is also the function from which the exception should have been thrown).</p><p>So we can’t throw an exception. Could the browser at least warn us when we forget to install a reject handler? This time, the answer is: sort of. The problem is that you can install a reject handler on a promise at any time, even longer after it has been rejected. To illustrate this, let’s slightly rewrite the previous example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a0fd9d3a51d1e2f74d32668ae0effb2/href">https://medium.com/media/7a0fd9d3a51d1e2f74d32668ae0effb2/href</a></iframe><p>At what point should the browser conclude that we forgot to install a reject handler on the promise <strong>p</strong>? Chrome takes the strategy to warn you when we return from <strong>g</strong> without having a catch handler installed on <strong>p</strong>. However, this leads to false positives, as running the above code in a console will illustrate.</p><p>Firefox takes a different strategy: it warns you when <strong>p</strong> is garbage collected without having a reject handler installed to it. This has the advantage that it doesn’t lead to false positives, because we know for sure that a reject handler can’t be installed after <strong>p</strong> has been garbage collected.</p><p>Unfortunately, this strategy is not without problems either: by the time <strong>p</strong> is garbage collected, we no longer know what the stack looked like when<strong> p</strong> was created. So even if we can tell that we forgot to install a reject handler on a promise, we still don’t know where that promise came from. That’s not very useful.</p><p>To be able to tell where a promise came from, we need to store a snapshot of the call stack with each promise when it is created. This is known as the <em>asynchronous call stack</em>, and it allows you to inspect what sequence of calls led up to the creation of a promise.</p><h4>Mistake 2: Forgetting to Return a Promise From a Fulfilled Handler</h4><p>Recall that a if a fulfilled handler returns a promise, the promise returned by the <strong>then</strong> method will adopt the same state as <em>that</em> promise, instead of the original promise on which the <strong>then</strong> method was called. This allows us to write code like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38ad8752aceb887f967df3407c9b8031/href">https://medium.com/media/38ad8752aceb887f967df3407c9b8031/href</a></iframe><p>Note that the first fulfilled handler is synchronous (i.e. it returns its result immediately), whereas the second one is asynchronous (i.e. it returns a promise). Because fulfilled handlers can return a promise, this allows us to chain both synchronous and asynchronous operations together.</p><p>A common mistake that people make when chaining operations together this way is forgetting to actually return the promise from the fulfilled handler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7980e178710300ddbffbed92652e038/href">https://medium.com/media/d7980e178710300ddbffbed92652e038/href</a></iframe><p>Mistakes like these are tricky because they do not prevent any of the subsequent operations from being executed, but they <em>do</em> stop the result of the asynchronous operation from being propagated, as the above example illustrates.</p><p>Theoretically, a linter could help us find mistakes such as these, but note that code like the above does not always indicate a bug: sometimes you really want to start an asynchronous operation inside a fulfilled handler without making it into a dependency of the next operation in a chain.</p><h4>About Jobs and Jobs Queues</h4><p>The mistakes we discussed so far were fairly straightforward. The next mistakes are somewhat more subtle, so diving into these, it’s worthwhile to quickly review how promises are supposed to work. In particular, we are interested in how or when completion handlers (i.e. fulfilled or reject handlers) are called.</p><p><a href="http://www.ecma-international.org/ecma-262/6.0/">The ECMAScript® 2015 Language Specification</a>, which is now the normative specification for promises, requires that promise completion handlers (i.e. fulfilled or reject handlers) are called asynchronously. To accomplish this, it defines the notion of Job Queues.</p><p>In <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-jobs-and-job-queues">section 8.4</a> of the specification, a Job is defined as “an abstract operation that initiates an ECMAScript computation when no other ECMAScript computation is currently in progress”. In other words, a Job represents some JavaScript code that is to be executed when no other JavaScript code is currently running.</p><p>To schedule the execution of a Job, an ECMAScript implementation creates a so called PendingJob record, representing the Job to be executed, and enqueues it on a Job Queue. The specification defines a Job Queue as “a FIFO queue of PendingJob records”. In other words, a Job Queue is a queue of Jobs to be executed.</p><p>Every ECMAScript implementation has at least two Job Queues, known as ScriptJobs and PromiseJobs. The former is used to schedule the execution of module code, the latter to schedule the execution of then-handlers when a promise becomes settled.</p><p>The specification requires that PendingJob records from a single Job Queue are always processed in FIFO order. However, it does not define the order in which multiple Job Queues are serviced: an ECMAScript implementation may interleave the processing of PendingJob records from one Job Queue with those of one or more other Job Queues.</p><p>As an aside, one interesting consequence of this definition is that it apparently allows for arbitrary module code to be executed between consecutive completion handlers. At the time of this writing, none of the major ECMAScript implementations have implemented modules, so I don’t know if this is how things will end up being implemented, but technically speaking the specification allows for it.</p><h4>Why We Need Job Queues</h4><p>In the previous section, we stated that the ECMAScript® 2015 Language Specification requires that completion handlers are called asynchronously. To accomplish this, it introduces the notion of Job Queues. But why do we need all this complexity? Why can’t we simply call our completion handlers synchronously? That way, we wouldn’t need Job Queues in the first place.</p><p>I was actually wondering about this myself, so I thought it’d be worthwhile to spend some time talking about it. If you aren’t interested in this, you can safely skip to the next section.</p><p>As it turns out, there are several good reasons to require completion handlers to be called asynchronously. To start with, it is very easy to run out of stack space when completion handlers are called synchronously. To illustrate how this can happen, consider the following example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10a0696b824839f10cc4b451ee151dd1/href">https://medium.com/media/10a0696b824839f10cc4b451ee151dd1/href</a></iframe><p>The function <strong>times </strong>takes a callback function and a count as argument. The callback function represents an asynchronous operation (i.e. it returns a promise) that will be called count times, in such a way the each operation is started when the previous one has completed.</p><p>Because the callback function returns a promise, we cannot write this function as an ordinary for loop. Instead, we use a concept known as <em>tail recursion</em>. With tail recursion, a function calls itself recursively as the last thing it does. This is semantically equivalent to an ordinary loop, in the sense that it will cause the same code to be executed in the same order.</p><p>Although ordinary loops and tail recursion are semantically equivalent, internally they are often implemented quite differently: going to the next iteration of an ordinary loop is typically implemented as a simple jump, whereas going to the next step of a tail recursion pushes another call frame on the stack. Because of this, ordinary loops will never run out of stack space, but tail recursion does.</p><p>Some languages, such as Scheme, will actually convert tail recursion to ordinary loops internally. This allows you to write tail recursive code without having to worry about running out of stack space. Languages such as these are said to support tail recursion. Unfortunately, JavaScript is not one of them.</p><p>Because JavaScript does not support tail recursion, we have to be careful about stack overflow when writing tail recursive code. Now consider what happens if completion handlers were called synchronously, and we use the function <strong>times</strong> as in the example here below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f11eb70a00996efe0913da992bd4f1c/href">https://medium.com/media/3f11eb70a00996efe0913da992bd4f1c/href</a></iframe><p>Because the callback function returns a promise that is already fulfilled, when completion handlers are called synchronously, any completion handler we install on this promise is called immediately. In this scenario, every time we go to the next step of the tail recursion, all previous calls to <strong>times</strong> are still on the stack. Since the JavaScript stack is relatively small, we will run out of stack space long before the loop completes.</p><p>In contrast, when completion handlers are called asynchronously, they are not called until there is no other JavaScript code on the stack. In this scenario, every time we go to the next step of the tail recursion, none of the previous calls to <strong>times</strong> are on the stack anymore, so we will never run out of stack space.</p><p>There is one other important reason for completion handlers to be called asynchronously: promises are also used by the DOM itself. More specifically, a DOM function is allowed to return a promise, to be resolved when some asynchronous operation completes. The ServiceWorker APIs makes heavy use of promises, to name one example.</p><p>DOM functions are typically written in C++. Such code often has strong assumptions about the state of the system that must hold in order to avoid a crash. From this point of view, your completion handler amounts to untrusted user code, because it can change the state of the system in arbitrary ways, potentially breaking one or more of these assumptions.</p><p>Consider what happens if completion handlers were called synchronously, and you installed at least one completion handler on a promise returned by a DOM function. When the DOM function resolves this promise, your completion handler is called immediately. Since your completion handler is untrusted user code, this operation is unsafe.</p><p>In contrast, when completion handlers are called asynchronously, they are not called until after we’ve returned from the DOM function. This makes it possible to safely resolve a promise from within a DOM function.</p><h4>Mistake #3: Assuming Fulfilled Handlers Are Called in the Same Order as They Are Defined</h4><p>Another common mistake that people make when writing promise code is assuming that completion handlers are called in the same order as they are defined. To understand the problem, consider the following example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5df976cbaad0a5c0c6acee8c8f1043d4/href">https://medium.com/media/5df976cbaad0a5c0c6acee8c8f1043d4/href</a></iframe><p>The function <strong>f </strong>takes a promise as argument, and installs a fulfilled handler <strong>f1</strong> on it. When the promise is resolved, <strong>f1</strong> sets the global variable <strong>value</strong> to “TWO”. It then creates a second promise, and installs a fulfilled handler <strong>f2 </strong>on it. When the second promise is resolved, <strong>f2</strong> logs <strong>value </strong>to the console.</p><p>If we only had knowledge about <strong>f</strong>, we might erroneously assume that <strong>f2</strong> will be called immediately after <strong>f1</strong>, so that “TWO” will be logged to the console. However, since we installed two additional fulfilled handlers on the promise passed to <strong>f</strong>, namely <strong>f3</strong> and <strong>f4, </strong>what actually happens is this:</p><p>According to the ECMAScript® 2015 Language Specification, when the promise is resolved, these fulfilled handlers will not be called immediately, but instead will be scheduled on a Job Queue. Consequently, when the promise is resolved, the fulfilled handlers will be scheduled in the order <strong>f3, f1, f4:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*m4qBj720mHVwqdHmwlRKNw.png" /></figure><p>By the time <strong>f1</strong> is executed, <strong>f4</strong> is still on the Job Queue, so <strong>f2 </strong>will be scheduled <em>after</em><strong> f4</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*p7R2EFxDfDWQqToVm_Aokw.png" /></figure><p>The underlying problem here is the same as with exception handling: it breaks the principle of locality of reference. It is impossible to tell the exact behavior of the function <strong>f</strong> without also looking at its surrounding context, and this makes it hard to write code that is correct.</p><h4>About Tasks and Microtasks</h4><p>In the previous sections, we’ve seen how the ECMAScript® 2015 Language Specification defines the asynchronous behavior of promise completion handlers in terms of Jobs and Job Queues. However, an ECMAScript implementation is always embedded in a host environment. A host environment completes the capabilities of the scripting language by providing it with objects and facilities to interact with.</p><p>Traditionally, web browsers have been the most popular host environment for ECMAScript implementations. To fully understand how promises are <em>supposed</em> to behave, we thus need to integrate the processing model of the browser with that of ECMAScript. In this section, we will complete our understanding of promises by looking at the <a href="https://html.spec.whatwg.org/">HTML specification</a>.</p><p>Section <a href="https://html.spec.whatwg.org/#integration-with-the-javascript-job-queue">8.1.3.6</a> of the specification states that: “the definitions … in [The ECMAScript® 2015 Language Specification] are not sufficiently flexible to integrate with HTML as a host environment”. To work around this, the specification introduces a number of “willful violations” to the The ECMAScript® 2015 Language Specification. In particular, it replaces the notion of Job Queues as with its own notion of Microtask Queues.</p><p>In other words: in the browser, the Microtask Queue replaces the Job Queue for scheduling the execution of then-handlers. The semantics of the former thus governs the semantics of the latter. Before we can explain Microtask Queues, however, we first need to introduce regular Task Queues. Task and Microtask Queues are intimately related, so it is impossible to explain one without the other.</p><p>Each Browsing Context (i.e. tab or iframe) or worker has an Event Loop. Event loops are used to coordinate events, user interaction, scripts, rendering, networking, and so forth. Each Event Loop has one or more Task Queues. The HTML specification defines a Task Queue as “an ordered list of tasks”. Tasks are defined as algorithms that are responsible for such work as dispatching an Event at a particular EventTarget.</p><p>The event loop continually removes the oldest Task from one of its Task Queues and runs it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*HKqZvCCFzKhG70QE-EKKEg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*w4cOY5gEdhqkpKatxdJe0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*IiUtkGiQH_It9DHb3HDbQw.png" /></figure><p>Each Event Loop also has a single Microtask Queue. The HTML specification defines a Microtask as “a task that is originally to be queued on the microtask queue rather than a task queue”.</p><p>That’s a somewhat circular definition, and doesn’t really help to explain what Microtasks are for. Perhaps the best way to think about Microtasks is as high-priority tasks: while there are any pending Microtasks, browsers should run those first, before any pending regular Tasks.</p><p>To enforce the requirement that no pending regular Tasks are run while there are any pending Microtasks, browsers perform a so called Microtask Checkpoint each time after it has run a regular task. During a Microtask Checkpoint, the event loop continually removes the oldest Microtask from its Microtask Queue and runs it, until the Microtask Queue becomes empty:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*v_y1PyQ5TLsRWNJz1d8uSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*2iR0_yRLvPwWskPzT18uOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*jOhgySkeQoepLjkEfmSFMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*GW5_4vGsFrg9JVa8JbSOsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*zjwjprVBmFJYfX_2Lz-czg.png" /></figure><h4>Why We Need Microtasks</h4><p>In the previous section, we’ve seen that the browser replaces the ECMAScript Job Queue with a Microtask Queue. As with Job Queues, it may not be immediately obvious why we need this additional complexity: why can’t we simply use regular Tasks to schedule the execution of completion handlers?</p><p>The answer is that using Microtasks to execute completion handlers guarantees that all pending completion handlers will be executed before the next Event is dispatched. This makes it much easier to reason about promise code: we may not be able to assume that our completion handlers are called in the same order as they show up in the code, but at least we can assume they are called before the next event is dispatched.</p><p>To understand why this is important, imagine what would happen if browsers used regular Tasks instead of Microtasks to execute completion handlers: in this case, the next Event may be dispatched before all pending completion handlers have been executed. Dispatching an Event can cause arbitrary client code to run, so the state of the world can change arbitrarily between the execution of one completion handler and the next.</p><p>This is not unlike the kind of problems you run into with multithreaded code, where the state of the world can change arbitrarily between the execution of one <em>instruction</em> and the next. Things are not quite as bad with promise code, since at least the completion handlers themselves are guaranteed to be atomic, but even so, the resulting code would be very hard to reason about. By replacing the Job Queue with the Microtask Queue, the HTML specification manages to avoid these issues.</p><p>In contrast, the ECMAScript® 2015 Language Specification does not address the issue of interleaving Events with completion handlers at all: the event model is strictly a property of the host environment, not the ECMAScript implementation itself. The only thing the specification cares about is that completion handlers are called asynchronously, and for this the notion of Job Queues is sufficient (there is no need to distinguish between Jobs and Microjobs, for instance).</p><h4>Mistake 4: Assuming That Browsers Actually Implement the Spec Correctly</h4><p>After this detour into the land of web specifications, we’re now ready to talk about the last category we want to look into, which is assuming that browsers actually implement the spec correctly.</p><p>According to the spec, all pending completion handlers should be called before the next event is dispatched. The idea is that this makes it much easier to reason about promise code.</p><p>Unfortunately, the web being the web, several of the major browsers currently implement Microtasks incorrectly. To illustrate the problem, take a look at the following JSbin (based on a more elaborate version by Jake Archibald):</p><p><a href="http://jsbin.com/notigi/edit?js,console,output">JS Bin</a></p><p>When you click on the blue square, the resulting event is dispatched to the inner div first. Within the click event listener on the inner div, we use <strong>resolve</strong> to schedule a completion handler. This completion handler should be executed before the next click event is dispatched to the outer div. The result should be that the following is logged to the console:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9d015d61ea05506798d9284a535097c/href">https://medium.com/media/d9d015d61ea05506798d9284a535097c/href</a></iframe><p>Unfortunately, only Chrome seems to get this right (I did not test it on Edge). On both Firefox and Safari, clicking the blue square causes the following to be logged to the console instead:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c517407098f32def98598bf7082a15a/href">https://medium.com/media/7c517407098f32def98598bf7082a15a/href</a></iframe><p>Apparently, these browsers dispatch both click events before executing the completion handlers. I don’t fully understand why this happens, but the implications are clear: the guarantee that all pending completion handlers are called before the next event is dispatched doesn’t hold in these browsers.</p><p>At first glance, this looks like it is really bad. As we’ve seen in the previous section, this can cause the state of the world to change arbitrarily between the execution of one completion handler and the next. Luckily for us, however, it looks like not all bets are off:</p><p>The following is speculative, but as far as I can tell, once the above browsers start executing completion handlers, they will keep executing then-handlers before dispatching the next event, as they should. This suggest that Microtask Checkpoints are implemented correctly, but are either not always performed when they should (i.e. each time after running a regular Task), or performed too often.</p><h4>Conclusion</h4><p>This was a long read, so if you made it this far, then I admire your patience :-)</p><p>We covered a lot of material in this post: we talked about how to do error handling with promises, how common mistakes with error handling can cause your promise code to fail silently, and why it is difficult for browsers to accurately warn for these mistakes. We also took a quick look at what happens when you forget to return a promise from a fulfilled handler, which is another common mistake.</p><p>We then took a closer look at how the behavior of promises is specified, and in particular the order in which completion handlers are called. As we have seen, this does not always happen in the order that you expect. Even if you’ve written your code correctly, it may still not behave like you expect, because browser don’t always implement the spec correctly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6a68adc2163" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The drawbacks of callbacks, or why promises are great.]]></title>
            <link>https://medium.com/@ejpbruel/the-drawbacks-of-callbacks-or-why-promises-are-great-5dedf2c98c67?source=rss-e27f1a78e27a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dedf2c98c67</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Eddy Bruel]]></dc:creator>
            <pubDate>Mon, 25 Jan 2016 15:55:38 GMT</pubDate>
            <atom:updated>2016-01-26T20:13:00.260Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the first in a series of two posts that I intend to write on promises. Promises are a software abstraction that is part of ECMAScript 6, and make it much easier to write asynchronous code. We use promises extensively in the Firefox devtools, so I originally wanted to write about some of the pitfalls of working with promises that we’ve encountered in practice.</p><p>As I started writing, however, the post became much longer than I anticipated, so I decided to split things up. This post will be about how promises make it easier to write asynchronous code. My next post will be about how promises do not necessarily make it easier to write <em>correct</em> asynchronous code.</p><p>This post consists of two main parts. In the first part, we’ll introduce callbacks, how they can be used to write asynchronous code, and what some of their drawbacks are. This will set the stage for part two, in which we’ll introduce promises, and how they address some of the drawbacks of callbacks.</p><h4>Using callbacks to write asynchronous code</h4><p>Let’s say we wanted to write a function to asynchronously load some data from a server using a HTTP GET request. We can write such a function using callbacks. A callback is a function that is passed as an argument to another function, and will be called by this other function at some future point, usually when some kind of operation completes.</p><p>If we implemented the above function using callbacks, we’d probably end up with something like this (for the sake of simplicity, we’ll ignore error handling for now):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26d42c6552530855fdd5e01ecd817b37/href">https://medium.com/media/26d42c6552530855fdd5e01ecd817b37/href</a></iframe><p>For those of you who’ve never written asynchronous code before, let’s quickly go over what this code does:</p><p>The call to request.send() on line 7 sends the HTTP GET request to the server. However, because we passed true as the third argument to the call to request.open() on line 6, request.send() does not wait for the response to arrive, but instead returns immediately after sending the request.</p><p>Because of this, we cannot return the response text immediately after the call to request.send(), since it will not be available until the response arrives. What we need is some way to get the response text to our caller, without having to wait for the response to arrive.</p><p>To accomplish this, we add an event listener. An event listener is a function that the browser calls automatically when some event happens. In our case, we are interested in the load event, which happens when the response arrives. To add an event listener for the load event we assign a function to the request.onload field on line 3.</p><p>Some time after we’ve returned to our caller, the response will arrive, and the event listener will be called. At this point, the response text will be available, and we can access it on the request.responseText field (note that, because JavaScript supports closures, we can still access the request variable from the event listener after the get function itself has gone out of scope).</p><p>We cannot simply return the response text from the event listener, however, because that function is called by the browser, not our original caller. To get the response text to our caller, we pass the response text as an argument to another function instead of returning it.</p><p>If that sounds confusing, an example of how the get function can be used might help to clear things up:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d010aa2557d6671e1e1ac7ff0edd9f8/href">https://medium.com/media/3d010aa2557d6671e1e1ac7ff0edd9f8/href</a></iframe><p>When we call the get function on line 1, it will not execute the callback that we passed as its second argument until it has the necessary information to do so, so line 4 will be executed next. Only when the response arrives will the callback be called, and line 2 be executed.</p><p>This approach of passing the result of a function call to a second function instead of returning it directly is a common pattern, and is known in the Computer Science literature as Continuation Passing Style, or CPS (one way to look at the callback in the above example is as a function representing the rest of the computation, or continuation).</p><h4>Error handling with callbacks</h4><p>A GET request can fail for a number of reasons. Maybe the URL we requested did not exist, or there was a connection error. Or the HTTP server received the request, but was unable to deal with it, so it sent an error response instead.</p><p>When we’re writing synchronous code, error handling is straightforward: when an error occurs, we simply throw an exception. In asynchronous code, things are not quite as simple, because the error may occur long after we’ve returned to our caller.</p><p>To illustrate how we can do error handling in asynchronous code, let’s implement a new version of the get function that we wrote earlier, with proper error handling added:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dccab943d0f5482e18834eb2afe8be56/href">https://medium.com/media/dccab943d0f5482e18834eb2afe8be56/href</a></iframe><p>In the this function, the callback takes two arguments instead of one. This is a common idiom that has been popularized by Node.js. The first argument is used to indicate that an error occurred. The remaining arguments are used to pass the result if the request completed successfully. In the latter case, the error argument should always be null.</p><p>When sending a HTTP GET request, the event listener for the error event is called when anything unexpected happens, such as a broken connection. However, it is not called when the server sends back an error response. In this case, the event listener for the load event is called, just as if the request completed successfully. This is why we explicitly check the status code of the response, and raise an error if it is anything other than 200 (HTTP OK).</p><h4>Why callbacks don’t scale</h4><p>As we’ve seen, we can use callbacks to write asynchronous functions that are robust in the face of errors. Callbacks are a nice mechanism for this because they are relatively easy to understand and reason about. That being said, they are not without problems.</p><p>The biggest problem with callbacks is that they do not scale well for even moderately complex asynchronous code. The resulting code often becomes hard to read, easy to break, and hard to debug.</p><p>To illustrate some of the problems with callbacks, let’s implement an asynchronous function that loads three files from a server, using the asynchronous get2 function we wrote earlier:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73fd3e3be7b1cffb53a0bf746dbb27a1/href">https://medium.com/media/73fd3e3be7b1cffb53a0bf746dbb27a1/href</a></iframe><p>A few things immediately stand out from this function. The first is that in each callback, we have to explicitly check if an error occurred, and immediately abort the entire operation if it did. This sort of boilerplate code is very repetitive to write, and can easily lead to us forgetting to check for an error somewhere. When this inevitably happens, the resulting bug is often hard to find.</p><p>Another thing that stands out is that each call to get introduces another level of indentation. In this particular example, it doesn’t look too bad, but it’s not too hard to come up with a more complex scenario, where the indentation ends up walking all the way off the right of your screen. This makes the resulting code hard to read.</p><h4>Diving deeper into callback hell</h4><p>Most people would probably agree that the getMultiple function doesn’t look particularly nice. However, it’s also needlessly inefficient: we don’t start the next request until the previous one has completed, even though they do not depend on each other in any way. It would be much nicer if we could start all three requests at the same time, and then wait for all of them to complete.</p><p>To further illustrate some of the problems with callbacks, let’s reimplement our previous version of getMultiple so that all three requests are started at the same time. The result would probably end up looking something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/876540f2d8851f0ec7e38b35854b6084/href">https://medium.com/media/876540f2d8851f0ec7e38b35854b6084/href</a></iframe><p>Whenever one of the HTTP GET requests completes, we store its result in an array, and increment a counter that keeps track of the number of completed requests. When this counter reaches 3, we call the callback with the array as the final result. If any of the requests fail with an error, we pass the error to the callback, indicating that the entire operation has failed.</p><p>Note that if an error occurs, we set the callback to null. This is necessary because even though the entire operation should fail if any of the requests fail, it should fail only once. Because additional requests could fail after the first one, if we don’t set the callback to null after the first time it is called, we can end up calling it a second time.</p><p>Hopefully, the above examples illustrate why using callbacks can lead to asynchronous code that is both unwieldy and fragile (forgetting to set the callback to null in our last example would have lead to some very strange and hard to debug behaviour!). People in the Node community refer to this affectionally (not really) as callback hell.</p><h4>Introducing promises</h4><p>Because callbacks are cumbersome to work with, people have tried to come up with abstractions to make writing asynchronous code less painful to work with. This is where promises enter the picture. A promise represents an asynchronous operation. To create a promise, we call the Promise constructor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/700b1bc56816f459b7f1a01ab4203bab/href">https://medium.com/media/700b1bc56816f459b7f1a01ab4203bab/href</a></iframe><p>The Promise constructor takes an <strong>executor</strong> function as parameter. We’re going to implement the asynchronous operation that our promise represents within this function.</p><p>When the Promise constructor is called, it immediately calls the executor function, and passes it a <strong>resolve</strong> and a <strong>reject</strong> function as arguments:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0a90a825d26b6ba124c17c3f33332e9/href">https://medium.com/media/c0a90a825d26b6ba124c17c3f33332e9/href</a></iframe><p>The resolve and reject function take a similar role to the callback function when using callbacks to write asynchronous code: the resolve function is called when the asynchronous operation completed successfully, and the reject function when an error occured.</p><p>The resolve function takes a single parameter, which represents the result of the asynchronous operation. Similarly, the reject function takes an error value as parameter.</p><h4>Using promises to write asynchronous code</h4><p>The above description of how to create a promise is admittedly somewhat abstract. Let’s see if we can make things a bit more concrete by reimplementing the get2 function we wrote earlier using promises instead of callbacks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e14337c8ac395285f41c59673408e4e/href">https://medium.com/media/2e14337c8ac395285f41c59673408e4e/href</a></iframe><p>Note how this version of get looks very similar to the previous, callback-based version. Nevertheless, there are a few key differences. Most importantly, this version of get no longer takes a callback function as parameter, but returns a promise instead.</p><p>Since the get function no longer takes a callback function as parameter, you might wonder how we can specify a function to be called after the HTTP GET request completes. As we’ll explain in a bit, we can use the promise returned by the get function for this.</p><h4>A quick word on promise states</h4><p>Before we continue, we should talk about promise states for a bit. This will make the subsequent sections easier to understand.</p><p>Conceptually, a promise can be in either of three states:</p><ul><li>When the asynchronous operation is still in progress, the promise said to be <strong>pending</strong>.</li><li>When the resolve function is called, the promise is said to be <strong>fulfilled</strong>.</li><li>When the reject function is called, the promise is said to be <strong>rejected</strong>.</li></ul><p>A promise always starts out in the pending state, and from there transitions to either the fulfilled or rejected state. After a promise is either fulfilled or rejected, it is said to be <strong>completed</strong>, and thereafter never changes state again.</p><p>Once nice consequence of this is that if we call the resolve or the reject function when the promise is already completed, this subsequent call is automatically ignored. This is especially useful if we have an asynchronous operation that is composed of multiple asynchronous sub-operations: we want the entire operation to fail if one of its sub-operations fails, but we don’t want the entire operation to fail a second time when one of its remaining sub-operations fails after that.</p><p>As we’ve seen when we implemented the getMultiple2 function, when using callbacks to write asynchronous code, we have to explicitly check whether the entire operation already failed, so we don’t end up calling the callback function twice. When using promises to write asynchronous code, this is handled automatically, so we don’t have to write this kind of boilerplate code.</p><h4>Adding then-handlers</h4><p>When using callbacks to write asynchronous code, each asynchronous function takes a callback function as parameter. This callback function is called when either the asynchronous operation completed successfully, or an error occurred. When we call the asynchronous function, we can pass it any function we like as the callback function to specify what should happen after the underlying operation completes.</p><p>In contrast, when using promises to write asynchronous code, the resolve and reject function are passed to the executor function by the Promise constructor. If we cannot define the resolve and reject function ourselves, how can we specify what should happen after the promise is completed? This is where then-handlers come in.</p><p>Then-handlers can be thought of as event handlers for promises: they will be called automatically when a promise is completed. To add a then-handler to a promise, we call the then method on the promise:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e56429af2f982200af865db4c8f9be1/href">https://medium.com/media/7e56429af2f982200af865db4c8f9be1/href</a></iframe><p>The then method takes an onFulfilled and an (optional) onRejected function as parameters. The onFulfilled function will be called when the function is fulfilled. It takes a single parameter, which is the value that was passed to the resolve function (unless that value was another promise. More on that later!). Similarly, the onRejected function will be called when the promise is rejected. It too takes a single parameter, which is the error value that was passed to the reject function.</p><p>In what follows, we will refer to the onFulfilled and onReject function as the <strong>fulfilled</strong> and <strong>catch handler</strong>, respectively.</p><p>When using promises to write asynchronous code, each asynchronous function returns a promise. To specify what should happen after the underlying asynchronous operation completes, we call the asynchronous function, and then add a then-handler to the resulting promise, passing any function we like as the fulfilled handler.</p><p>To illustrate this, let’s add a then-handler to the promise returned by the get3 function we wrote earlier:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9fb4f684ecb1da305a2c09d2be408ad/href">https://medium.com/media/c9fb4f684ecb1da305a2c09d2be408ad/href</a></iframe><h4>Why are promises better?</h4><p>At this point, you might be wondering why we went through all the trouble of reimplementing the get function using promises instead of callbacks. We’ve added a lot of new abstractions, and the resulting code doesn’t look any simpler. In fact, rather than reduce the number of callbacks, we’ve actually doubled them! Why would you use promises if all they do is add to the number of abstractions you have to keep in your head?</p><p>The answer to that is that promises don’t begin to really outshine callbacks until you start to compose asynchronous operations. As we’ve seen when using callbacks to write asynchronous code, it’s exactly when we tried to compose asynchronous operations that the callback approach started to break down.</p><p>As it turns out, promises have a two interesting properties that make it particularly easy to compose asynchronous operations. We will go over both of those properties first, and then show how they can be used.</p><h4>Chaining then-handlers</h4><p>When you call the then method on a promise, it will return a second promise. When the original promise is fulfilled, this second promise is resolved using the value returned by the fulfilled handler. In other words: the promise returned by the then method adopts the same state as the promise we called the then method on.</p><p>If that sounds confusing, hopefully the following example will help clear it up:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0bac24f803c3ed0b3f3842ee53e83a0/href">https://medium.com/media/b0bac24f803c3ed0b3f3842ee53e83a0/href</a></iframe><p>This property of then-handlers allows you to specify multiple operations to be performed after the original promise is completed, in such a way that each operation depends on the result of the one that precedes it.</p><p>So far, we only specified what happens if the original promise is fulfilled. If the original promise is rejected instead, the second promise is rejected with the same value as the original promise. However, if we also added a catch handler, the second promise is instead resolved with the value returned by the catch handler. One way to think of this is that the catch handler catches the rejection of the original promise, preventing the second promise from being rejected as well.</p><h4>Nesting promises</h4><p>Earlier we briefly mentioned that the fulfilled handler is called with the value passed to the resolve function, unless that value is a promise. When a promise is resolved with another promise, it instead adopts the state of that promise. In other words, any then-handlers on the original promise will behave as if they were added to the promise with which the original promise was resolved.</p><p>If that sounds confusing, hopefully the following example will help clear it up:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6ab490424630e6ad590f3dc27e7e15d/href">https://medium.com/media/b6ab490424630e6ad590f3dc27e7e15d/href</a></iframe><p>Because the promise returned by the then method is resolved using the value returned by either the fulfilled or catch handler (depending on whether the promise is fulfilled or rejected), if this value is a promise, the promise returned by the then method also adopts the state of that promise:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49d5d360f354c1f17c27ed4fe63ce853/href">https://medium.com/media/49d5d360f354c1f17c27ed4fe63ce853/href</a></iframe><p>Combined with the previous property, this property of then-handlers allows you to specify multiple asynchronous operations to be performed, in such a way that each operation depends on the result of the one that precedes it.</p><h4>Using promises to compose asynchronous operations</h4><p>Now that we’ve seen some of the properties of promises that make it easy to compose asynchronous operations, let’s put this knowledge to use to rewrite the sequential implementation of getMultiple that we wrote earlier using promises instead of callbacks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e00c3821f43ccb1744b902717b096e63/href">https://medium.com/media/e00c3821f43ccb1744b902717b096e63/href</a></iframe><p>What’s immediately obvious is how much more compact this version is than the previous one. However, if you’ve never worked with promises before, it’s not immediately clear how this function works. So let’s go over that step by step.</p><p>The first thing to notice is that each call to get3 returns a promise. Furthermore, on each of these promises we then call its then method, which returns a second promise. In particular, the outermost return statement on line 2 returns the promise returned by the call to get(“one.js”).then(…).</p><p>What will this promise be resolved with? As we’ve seen, it will be resolved with the value returned by the fulfilled handler. This is the second outermost return statement on line 3, which returns get3(“two.js”).then(…). Since this is another promise, the outermost promise will eventually assume the same state as this one.</p><p>Similarly, the promise returned by the second outermost return statement will eventually assume the same state as the promise returned by the third outermost return statement on line 4. Finally, this promise will be fulfilled with the value returned by the innermost fulfilled handler on line 5.</p><p>The innermost fulfilled handler returns an array containing the result of each HTTP GET request. Because it is defined within the scope of the fulfilled handlers of each previous request, it has access to the results of these requests.</p><p>This is why the then method is so useful: given an asynchronous request, it allows you to define a new asynchronous request, which is composed of the original asynchronous request, followed by a second asynchronous request that depends on the value of the first one.</p><p>One thing we glanced over so far is how error handling works in this example. Recall that if we didn’t add a catch handler, and the original promise is rejected, the promise returned by the then method will also be rejected. Consequently, the fulfilled handler will never be called. As a result, if any of the requests fail, none of the subsequent requests will be initiated, and the promise returned by the getMultiple3 function will be rejected immediately. If you compare this with how we did error handling in the previous version of this function, it’s clear that this approach requires a lot less boilerplate.</p><p>So far, we’ve reimplemented the sequential version of getMultiple with promises. What about the parallel one (i.e. getMultiple2)? As it turns out, the Promise constructor has a built-in helper function that makes writing such functions a breeze:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8084e0be98c3ce4ddfa244ee26d9c2c8/href">https://medium.com/media/8084e0be98c3ce4ddfa244ee26d9c2c8/href</a></iframe><p>That’s it! That’s all there’s to it. This version of getMultiple has the same semantics as our previous one, so if any of the individual requests fail, the entire operation is aborted. I’m sure you’ll agree that this looks much simpler than what we had before.</p><h4>Conclusion</h4><p>We’ve seen how callbacks can be used to write asynchronous code, and what their drawbacks are. In particular, we’ve seen that the resulting code can quickly become unwieldy and fragile. We then introduced promises as an alternative to callbacks, and showed how they are used. Finally, we showed how promises improve upon callbacks by making it much easier to compose asynchronous operations.</p><p>Although promises are definitely an improvement on callbacks, they too are not without problems. In my next post, I intend to highlight some of the pitfalls of using promises that we’ve encountered.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dedf2c98c67" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>