Skip to content

Commit 66cc717

Browse files
authored
samples: some samples incorrectly called publishMessage without await (#2035)
I just noticed this while doing something unrelated.
1 parent c9a9656 commit 66cc717

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

samples/publishMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function publishMessage(topicNameOrId, data) {
5151
const topic = pubSubClient.topic(topicNameOrId);
5252

5353
try {
54-
const messageId = topic.publishMessage({data: dataBuffer});
54+
const messageId = await topic.publishMessage({data: dataBuffer});
5555
console.log(`Message ${messageId} published.`);
5656
} catch (error) {
5757
console.error(`Received error while publishing: ${error.message}`);

samples/publishMessageWithCustomAttributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async function publishMessageWithCustomAttributes(topicNameOrId, data) {
5555
// Cache topic objects (publishers) and reuse them.
5656
const topic = pubSubClient.topic(topicNameOrId);
5757

58-
const messageId = topic.publishMessage({
58+
const messageId = await topic.publishMessage({
5959
data: dataBuffer,
6060
attributes: customAttributes,
6161
});

samples/publishOrderedMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function publishOrderedMessage(topicNameOrId, data, orderingKey) {
7272
const topic = pubSubClient.topic(topicNameOrId, publishOptions);
7373

7474
// Publishes the message
75-
const messageId = topic.publishMessage(message);
75+
const messageId = await topic.publishMessage(message);
7676

7777
console.log(`Message ${messageId} published.`);
7878

samples/system-test/schema.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ describe('schema', () => {
383383
const topic = await createTopicWithSchema(id, schema.id, Encodings.Json);
384384
const sub = await createSub(id, topic.name);
385385

386-
topic.publishMessage({
386+
await topic.publishMessage({
387387
data: Buffer.from(
388388
JSON.stringify({
389389
name: 'Alberta',
@@ -419,7 +419,7 @@ describe('schema', () => {
419419
);
420420
const sub = await createSub(id, topic.name);
421421

422-
topic.publishMessage({
422+
await topic.publishMessage({
423423
data: Buffer.from(
424424
JSON.stringify({
425425
name: 'Alberta',
@@ -443,7 +443,7 @@ describe('schema', () => {
443443
const topic = await createTopicWithSchema(id, schema.id, Encodings.Json);
444444
const sub = await createSub(id, topic.name);
445445

446-
topic.publishMessage({
446+
await topic.publishMessage({
447447
data: Buffer.from(
448448
JSON.stringify({
449449
name: 'Quebec',

samples/typescript/publishMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function publishMessage(topicNameOrId: string, data: string) {
4747
const topic = pubSubClient.topic(topicNameOrId);
4848

4949
try {
50-
const messageId = topic.publishMessage({data: dataBuffer});
50+
const messageId = await topic.publishMessage({data: dataBuffer});
5151
console.log(`Message ${messageId} published.`);
5252
} catch (error) {
5353
console.error(

samples/typescript/publishMessageWithCustomAttributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function publishMessageWithCustomAttributes(
5858
// Cache topic objects (publishers) and reuse them.
5959
const topic = pubSubClient.topic(topicNameOrId);
6060

61-
const messageId = topic.publishMessage({
61+
const messageId = await topic.publishMessage({
6262
data: dataBuffer,
6363
attributes: customAttributes,
6464
});

samples/typescript/publishOrderedMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function publishOrderedMessage(
7272
const topic = pubSubClient.topic(topicNameOrId, publishOptions);
7373

7474
// Publishes the message
75-
const messageId = topic.publishMessage(message);
75+
const messageId = await topic.publishMessage(message);
7676

7777
console.log(`Message ${messageId} published.`);
7878

0 commit comments

Comments
 (0)