Category: Promises

Flow Control in Modern JS: Callbacks to Promises to Async/Await

JavaScript is regularly claimed to be asynchronous. What does that mean? How does it affect development? How has the approach changed in recent years? Consider the following code: result1 = doSomething1(); result2 = doSomething2(result1); Most languages process each line synchronously. The first line runs and return...

An Overview of JavaScript Promises

This tutorial covers the basics of JavaScript promises, showing how you can leverage them in your JavaScript development. The concept of promises is not new to web development. Many of us have already used promises in the form of libraries such as Q, when.js, RSVP.js, etc. Even jQuery has something called a Deferred ob...

Async Operations in React Redux Applications

This post was originally posted at Codebrahma. JavaScript is a single-threaded programming language. That is, when you have code something like this … … the second line doesn’t get executed till the first one gets completed. Mostly this won’t be a problem, since millions of calculations are performed b...

Simplifying Asynchronous Coding with Async Functions

The debut of Promises in JavaScript has lit the internet on fire—they help developers break out of callback hell and solve a lot of problems that have plagued the asynchronous code of JavaScript programmers everywhere. Promises are far from flawless, though. They still require callbacks, can still be messy in complex...

The Promise of a Burger Party

Mariko Kosaka with an elaborate and wonderful metaphor. What is a Promise in JavaScript? It’s like if you go to a restaurant and order a burger and a shake. The restaurant needs to prepare your food, so after you pay, you get a tray with a buzzer on it. The tray is the Promise. Direct Link to Article — Perm...

Quick Tip: What Are Factory Functions in JavaScript

You can’t get far as a JavaScript programmer without learning about functions and objects, and when used together, they are the building blocks we need to get started with a powerful object paradigm called composition. Today we’ll look at some idiomatic patterns for using factory functions to compose functi...

An Introduction to jQuery’s Deferred Objects

For a long time, JavaScript developers have used callback functions to perform several tasks. A very common example is to add a callback via the addEventListener() function to execute various operations when an event, such as click or keypress, is fired. Callback functions are simple and get the job done for simple cas...

Face Proximity Detection with JavaScript

Let’s suppose you’d like to let the visitors of your website make a video recording or take a picture of their face. How can you explain to them how close they’re supposed to sit to the camera? You could write lengthy instructions, but you know that today almost nobody reads the instructions. Probably, a ...

Preloading Images in Parallel with Promises

The topic of this article is actually quite specific. Recently, I faced a situation where I needed to preload a lot of images in parallel. With the given constraints, it ended up being more challenging than first expected, and I certainly learnt a lot along the journey. But first, let me describe the situation shortly ...

Promises in JavaScript Unit Tests: the Definitive Guide

Promises are becoming a common part of JavaScript code. The native Promise object is already supported by all the major browsers including Chrome, Firefox, and Safari. Despite making asynchronous code simpler, dealing with promises in unit tests is a hassle. You need to wire your test’s assertions into the callbacks ...