Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 811 Bytes

async.md

File metadata and controls

36 lines (26 loc) · 811 Bytes

Async Handling

Callbacks and promises living together... MASS HYSTERIA. Or not! This library handles both of your favorite async strategies.

Promises

All our library methods return promises, so if you're a promise-fan, just do what you normally do.

let client = new SparkPost(key);

client.templates.get(id)
  .then((data) => {
    // this the full API response body
  })
  .catch((err) => {
    // handle the sad error
  });

Callbacks

If you're more of a callbacker, that works too. Pass a callback as the last argument and it'll be handled like a regular, error-first callback.

let client = new SparkPost(key);

client.templates.get(id, (err, data) => {
  if (err) {
    // handle the sad error
    return;
  }

  // this is the full API response body
});