From 8a6ca3c83322e98e0bea96e1c4817e3821fe2f45 Mon Sep 17 00:00:00 2001 From: Kevin Grandon Date: Sat, 19 Dec 2015 13:32:16 -0800 Subject: [PATCH] Update README to include example of async function usage with key(). --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index b48b6df..29c7146 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,26 @@ fireproof.auth('my_auth_token').then(function() { }) ``` +### Async Functions + +This library returns promises and will work well with async functions. + +```javascript +// Pushing a record using an async function +var ref = fireproof.child('myref') +var pushref = ref.push({ /* some object */ }) + +// This is the key of the newly pushed location. +// Note that it is called on the result of ref.push, and not the result of an async function. +console.log(pushref.key()) + +var error = await pushref +if (error) { + console.error('Something went wrong pushing ' + pushref.key()) + console.error(error) +} +``` + ## Support IE back to 9.