Skip to content

Commit

Permalink
docs(samples): update samples to use async/await (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
muraliQlogic authored and JustinBeckwith committed Nov 12, 2018
1 parent aa9c442 commit e0b4518
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 468 deletions.
2 changes: 2 additions & 0 deletions samples/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
env:
mocha: true
rules:
no-console: off
no-unused-vars: off
6 changes: 3 additions & 3 deletions samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"node": ">=8"
},
"scripts": {
"ava": "ava -T 10m --verbose system-test/*.test.js",
"cover": "nyc --reporter=lcov --cache ava -T 10m --verbose test/*.test.js system-test/*.test.js && nyc report",
"mocha": "mocha system-test/*.js --timeout 600000",
"cover": "nyc --reporter=lcov --cache mocha test/*.test.js system-test/*.test.js --timeout 600000 && nyc report",
"test": "npm run cover"
},
"dependencies": {
"@google-cloud/pubsub": "^0.20.1",
"yargs": "^12.0.0"
},
"devDependencies": {
"mocha": "^5.2.0",
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0",
"nyc": "^13.0.0",
"proxyquire": "^2.0.0",
"sinon": "^7.0.0",
Expand Down
32 changes: 14 additions & 18 deletions samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,21 @@
// Imports the Google Cloud client library
const {PubSub} = require('@google-cloud/pubsub');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';
async function quickstart() {
// Your Google Cloud Platform project ID
const projectId = process.env.GCLOUD_PROJECT || 'YOUR_PROJECT_ID';

// Instantiates a client
const pubsubClient = new PubSub({
projectId: projectId,
});
// Instantiates a client
const pubsubClient = new PubSub({
projectId: projectId,
});

// The name for the new topic
const topicName = 'my-topic';
// The name for the new topic
const topicName = 'my-topic';

// Creates the new topic
pubsubClient
.createTopic(topicName)
.then(results => {
const topic = results[0];
console.log(`Topic ${topic.name} created.`);
})
.catch(err => {
console.error('ERROR:', err);
});
// Creates the new topic
const [topic] = await pubsubClient.createTopic(topicName);
console.log(`Topic ${topic.name} created.`);
}
quickstart().catch(console.error);
// [END pubsub_quickstart_create_topic]
Loading

0 comments on commit e0b4518

Please sign in to comment.