Build the future of communications.
Start Building for Free
  • By AJ Saulsberry
    Asynchronous JavaScript: Tools, Techniques, and Case Studies async-js-tools.png

    There are a number of asynchronous tools in JavaScript, and there are also asynchronous tools in popular libraries that extend JavaScript. And there are many uses for these technologies.

    You can learn about the fundamental asynchronous JavaScript tools in posts here on the Twilio blog: There is a post devoted to each technology, and they’re summarized in the post:

    Asynchronous JavaScript: A Comprehensive Guide

    When you’re learning any new programming tool or technique it’s helpful to have examples of how to use the code in realistic situations, so in addition to covering the fundamentals we have a series of posts showing practical demonstrations of how to use asynchronous code.

    Confirming SMS Message Delivery with RxJS Observables, Node.js, and Twilio Programmable SMS

    You’ll learn a couple of important things from this post: 1) how to create an Observable wrapper around an API request so your code gets a notification when the …

    Read More
  • By AJ Saulsberry
    Asynchronous JavaScript: A Comprehensive Guide async-js-guide.png

    Are you learning JavaScript and trying to understand asynchronous programming? Are you currently a JavaScript programmer who needs an overview of the asynchronous features of JavaScript? Or are you trying to decide which asynchronous technique best suits a programming task you’re trying to accomplish?

    If you identify with any of these descriptions — or even if you’re just looking for a refresher on a specific asynchronous technique — the Asynchronous JavaScript series here on the Twilio blog can help. The series covers everything from callbacks to the async and await keywords; and it even includes RxJS Observables, a widely-used external library for handling asynchronous tasks.

    Each of the posts includes complete source code for a runnable Node.js project demonstrating the technique covered in the post, and the posts are unified by a common case study so you can compare different approaches to the same task. The code for each post …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Choosing the Right Asynchronous Tool async-js-choosing.png

    Since its beginning as a primitive, unstandardized scripting language for web browsers, JavaScript has gained many features that better equip it for handling common programming tasks. Some of the most important improvements are in the area of handling asynchronous events like form submission, user interface interaction, and media management.

    The growth of server-side JavaScript enabled by Node.js has substantially expanded the range of project types and business challenges JavaScript can successfully address, adding new requirements for asynchronous processing. The popularity of web services as a design paradigm and REST APIs as an interaction standard have both added to the scope of asynchronous tasks for the language.

    The Node package management system, npm, makes it possible to easily integrate capabilities provided in open source libraries. Packages for asynchronous tasks have been some of the most successful of these, adding programming paradigms to JavaScript that were unimagined in the early days of …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Using Promises With REST APIs in Node.js async-js-apis-nodejs.png

    In JavaScript, like many programming languages, asynchronous processing can be used to handle tasks that take a long time to run or are potentially unresponsive. The JavaScript Promise object provides a way of monitoring their state and serves as a placeholder and container for the data they’ll eventually return — or not.

    Often it doesn’t matter when a Promise returns data and the members of a collection of Promises can be resolved independently without regard to timing. A function can perform asynchronous tasks that don’t depend on the data from, or the success of, other asynchronous tasks.

    But sometimes business rules or program design require that asynchronous actions are dependent on other asynchronous operations. For example:

    • Establishing a remote database connection must be preceded by loading configuration information from the file system.
    • Performing a REST API call to a weather API must be preceded by obtaining the user’s location from …
    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Introducing async and await async-js-async-await.png

    Asynchronous processing is one of the most important aspects of the JavaScript language. JavaScript is a single-threaded language, so it needs a mechanism to deal with the actions like performing time-intensive and potentially unreliable activities like making REST API calls, reading files from the disk, or interacting with user input.

    In JavaScript the mechanism used is an event loop, which processes a callback queue in order from oldest item to newest. Each item in the queue is a message that’s processed completely before moving on to the next next message. Each message is a function that returns a response to code elsewhere in the application. Functions used in this way are called callback functions.

    Because of callbacks, JavaScript can use a number of techniques for getting around its single-threaded nature to implement asynchronous processing. Unfortunately, some of those techniques, JavaScript Promises and RxJS Observables, force you to introduce at …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Using RxJS Observables with REST APIs in Node.js Async JS RxJS Observables Node js

    ReactiveX is an electrifying programming concept. It’s widely adopted in popular programming languages, including JavaScript. ReactiveX programs can react to data as it is emitted from a source, rather than get the data from it. This is a convenient way of handling data from sources like web APIs or WebSockets.

    In this post you’ll get hands-on experience doing ReactiveX programming with RxJS: ReactiveX for JavaScript. You’ll learn how to perform REST API calls to retrieve data asynchronously, manipulate it as it arrives, and perform subsequent calls based on the emitted data. You’ll also see how to perform other actions whenever data is emitted by an Observable.

    This post focuses on how to utilize RxJS Observables with REST API calls. The previous post in this series on Asynchronous JavaScript explains RxJS fundamentals:

    Understanding the case study project

    In this post you will see how …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Introducing ReactiveX and RxJS Observables async-js-reactivex-rxjs-observables.png

    Reactive Extensions (ReactiveX) are one of the most widely-adopted set of tools in programming today. ReactiveX libraries for JavaScript and other languages provide a way to operate on sequences of data as if they were events. This is a convenient way to handle data from asynchronous sources like web APIs: your programs can react to data as it is emitted from the source without tightly coupling the code that uses the data with the code that gets the data.

    In this post you’ll learn about the fundamental concepts of ReactiveX programming and get hands-on experience doing ReactiveX programming with RxJS for JavaScript. You’ll learn how to retrieve data asynchronously, manipulate it as it arrives, and handle errors. You’ll also see how RxJS Observables compare to JavaScript Promises.

    Introducing the ReactiveX API and the RxJS library

    Reactive Extensions, known as ReactiveX, is an application programming interface (API) enabling programming languages …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Refactoring Callbacks to Promises in Node.js Advanced JavaScript: Refactoring Callbacks to Promises

    If you know how the event loop mechanism works in JavaScript you know how it enables you to work with asynchronous events. You might also know how to refactor your code into separate functions to reduce the amount of nesting associated with a sequence of callback functions. If you work with web APIs you are probably familiar with the JavaScript request library, which is used to perform HTTP calls.

    You can put these skills together to retrieve remote data through an HTTP request and work with the call response asynchronously. But in doing so you’ll probably notice that code has at least one pitfall: the logical order of declared functions is reversed. That makes the code hard to read and maintain.

    With the node-fetch JavaScript library and Promise objects you can reduce nesting, known as the callback “Pyramid of Doom”, and organize your code in a more readable and logical …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Advanced Promises with Node.js Asynchronous JavaScript: Advanced Promises with Node.js

    JavaScript Promise objects are a considerable improvement over basic JavaScript callback functions. Promises provide an object that represents both the state of an asynchronous function and the values returned by it. The state indicates whether the promise is pending, fulfilled by a successfully completed operation, or rejected because of an error or other condition. When a promise is fulfilled its value is determined by the asynchronous operation executed by the promise.

    Promises can also be chained together to use the state of settled promises (resolved or rejected) and the promises’ values to control the flow of execution in your program. This is useful when you have a sequence of asynchronous operations to perform that each depend on the results of the previous operation: the next step in the chain isn’t performed until the preceding step is resolved. Chains of promises also include error propagation; errors in a …

    Read More
  • By Maciej Treder
    Asynchronous JavaScript: Introduction to JavaScript Promises Asynchronous JavaScript Introduction to Promises

    Asynchronous processing is one of the most important capabilities JavaScript acquired as the language matured. JavaScript’s async capabilities enable more sophisticated and responsive user interfaces. They also make it possible to implement a distributed web application architecture built on standards like SOAP and REST.

    JavaScript Promises are currently the most powerful and flexible asynchronous technology built into the language itself. This post will explain how they work and get you writing your own promises with some practical examples.

    Promises offer a number of advantages:

    • a promise can be called multiple times
    • promises can be chained together
    • promises can include error rejection events
    • errors in a chain of promises need only be handled once (error propagation)
    • promises can be used to wrap old-style callback functionality
    • promises always execute after the current execution stack is empty

    If you’re just starting out with asynchronous functionality in JavaScript the preceding points might not mean …

    Read More
  • Newer
    Sign up and start building
    Not ready yet? Talk to an expert.