Created
August 22, 2016 07:17
-
-
Save timmyw/333a211ea48437cfd6a76c85f1cb9edb to your computer and use it in GitHub Desktop.
Async/await
This file contains hidden or 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
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