Skip to content

Commit ecc7bcc

Browse files
committed
chore: various improvements after review
1 parent abfc3e3 commit ecc7bcc

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

09-behavioral-design-patterns/02-state-failsafe-socket/onlineState.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ export class OnlineState {
99
}
1010

1111
async _tryFlush() {
12-
let success = true
13-
while (this.failsafeSocket.queue.length > 0) {
14-
const data = this.failsafeSocket.queue[0]
15-
const flushed = await this._tryWrite(data)
16-
if (flushed) {
17-
this.failsafeSocket.queue.shift()
18-
} else {
19-
success = false
20-
break
12+
try {
13+
let success = true
14+
while (this.failsafeSocket.queue.length > 0) {
15+
const data = this.failsafeSocket.queue[0]
16+
const flushed = await this._tryWrite(data)
17+
if (flushed) {
18+
this.failsafeSocket.queue.shift()
19+
} else {
20+
success = false
21+
break
22+
}
2123
}
22-
}
23-
if (!success) {
24+
if (!success) {
25+
this.failsafeSocket.changeState('offline')
26+
}
27+
} catch (err) {
28+
console.error('Error during flush', err.message)
2429
this.failsafeSocket.changeState('offline')
2530
}
2631
}

09-behavioral-design-patterns/12-async-generator-check-urls/checkUrls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class CheckUrls {
66
async *[Symbol.asyncIterator]() {
77
for (const url of this.urls) {
88
try {
9-
const checkResult = await await fetch(url, {
9+
const checkResult = await fetch(url, {
1010
method: 'HEAD',
1111
redirect: 'follow',
1212
signal: AbortSignal.timeout(5000), // 5 secs timeout

09-behavioral-design-patterns/14-async-iterator-utilities/checkUrls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class CheckUrls {
66
async *[Symbol.asyncIterator]() {
77
for (const url of this.urls) {
88
try {
9-
const checkResult = await await fetch(url, {
9+
const checkResult = await fetch(url, {
1010
method: 'HEAD',
1111
redirect: 'follow',
1212
signal: AbortSignal.timeout(5000), // 5 secs timeout

09-behavioral-design-patterns/16-command/createPostStatusCmd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function createPostStatusCmd(service, status) {
1313
}
1414
},
1515
serialize() {
16-
return { type: 'status', action: 'post', status: status }
16+
return { type: 'status', action: 'post', status }
1717
},
1818
}
1919
}

0 commit comments

Comments
 (0)