-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated docs and examples for suppression, added async doc
- Loading branch information
1 parent
2acd01e
commit 7d279f3
Showing
7 changed files
with
66 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# 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. | ||
|
||
```javascript | ||
let client = new SparkPost(key); | ||
|
||
client.templates.get(id) | ||
.then((data) => { | ||
// this is either: | ||
// a) the `results` key of the API response body, or | ||
// b) 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. | ||
|
||
```javascript | ||
let client = new SparkPost(key); | ||
|
||
client.templates.get(id, (err, data) => { | ||
if (err) { | ||
// handle the sad error | ||
return; | ||
} | ||
|
||
// this is either: | ||
// a) the `results` key of the API response body, or | ||
// b) the full API response body | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters