Skip to content

Commit e809288

Browse files
praveenqlogicJustinBeckwith
authored andcommitted
docs(samples): updated samples code to use async await (#129)
1 parent 5aaa74c commit e809288

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

cloud-tasks/createTask.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Create a task for a given queue with an arbitrary payload.
2020
*/
21-
function createTask(project, location, queue, options) {
21+
async function createTask(project, location, queue, options) {
2222
// [START cloud_tasks_appengine_create_task]
2323
// [START tasks_quickstart]
2424
// Imports the Google Cloud Tasks library.
@@ -62,15 +62,10 @@ function createTask(project, location, queue, options) {
6262

6363
console.log('Sending task %j', task);
6464
// Send create task request.
65-
client
66-
.createTask(request)
67-
.then(response => {
68-
const task = response[0].name;
69-
console.log(`Created task ${task}`);
70-
})
71-
.catch(err => {
72-
console.error(`Error in createTask: ${err.message || err}`);
73-
});
65+
const [response] = await client.createTask(request);
66+
const name = response.name;
67+
console.log(`Created task ${name}`);
68+
7469
// [END cloud_tasks_appengine_create_task]
7570
// [END tasks_quickstart]
7671
}
@@ -122,7 +117,9 @@ const cli = require(`yargs`)
122117
if (module === require.main) {
123118
const opts = cli.help().parse(process.argv.slice(2));
124119
process.env.GCLOUD_PROJECT = opts.project;
125-
createTask(opts.project, opts.location, opts.queue, opts);
120+
createTask(opts.project, opts.location, opts.queue, opts).catch(
121+
console.error
122+
);
126123
}
127124

128125
exports.createTask = createTask;

0 commit comments

Comments
 (0)