Skip to content

Instantly share code, notes, and snippets.

@timmyw
Created August 22, 2016 07:17
Show Gist options
  • Save timmyw/333a211ea48437cfd6a76c85f1cb9edb to your computer and use it in GitHub Desktop.
Save timmyw/333a211ea48437cfd6a76c85f1cb9edb to your computer and use it in GitHub Desktop.
Async/await
import pgpromise from 'pg-promise'
import async from 'async'
let config = { pgConnectionStrings: {
contentcontrol: "postgres://apiservice:password@localhost:5432/contentcontroldb_development",
contentcontrolReadOnly: "postgres://apiservice:password@localhost:5432/contentcontroldb_development"}}
const pgp = pgpromise()
const db = pgp(config.pgConnectionStrings.contentcontrol)
async function dostuff(config, done) {
console.log('2')
let result
try {
let qry = 'SELECT * FROM api_tokens'
result = await db.many(qry)
console.log(done) // <--- why is this undefined here ?
} catch (err) {
console.log(err)
}
console.log('3')
done(result)
}
function wrapper(config) {
console.log('wrapper:start')
async.series([
(done) => { dostuff(config, done) }
], function(res) {
console.log('res', res)
console.log('wrapper:end')
return res
})
}
console.log('1')
dostuff(config)
console.log('4')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment