node v0.12.18
version: 1.0.0
A common way to get around nesting callbacks everywhere in JavaScript is to use promises. But these require chaining a bunch of "then" functions together to do anything, which is still cumbersome. Putting "await" before any promise let's you write linear looking code, which works great with Tonic and our object viewers that show you the value of the last expression:
// the old way require('request-promise')("") .then(function(status){ // do something with status }) // the new way! await require('request-promise')("")
Many libraries these days natively support promises, and npm is full of packages that add promise support to existing libraries. Here are a few of our favorites:
require("fs-promise") // promise based filesystem api
require("request-promise") // a wrapper around "request" for http stuff
require("glob-promise") // glob style filesystem queries
require("bluebird") // general promise library with lots of utilities

no comments

    sign in to comment