Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d60fb38

Browse files
Albert LiAlbert Li
Albert Li
authored and
Albert Li
committed
adding option for race condition set
1 parent 8776e4e commit d60fb38

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

‎src/test/concurrency.ts

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,47 @@ let concurrency = 5;
1414
// }
1515
// });
1616

17-
setTimeout(async () => {
18-
for (let i: number = 0; i < images.length; i += 5) {
19-
let _images = images.slice(i, i + 5);
20-
21-
console.log('batch image start: ', i);
22-
23-
await Promise.all(
24-
_images.map(async (value, index, array) => {
25-
console.log('image start: ', index + i);
26-
await fetch(value).then((res) => res.text());
27-
console.log('image end: ', index + i);
28-
}),
29-
);
30-
31-
console.log('batch image end: ', i);
32-
}
33-
}, 0);
17+
const requestOptions = {
18+
sendByOne: (images) => {
19+
setTimeout(async () => {
20+
for (let i: number = 0; i < images.length; i += 1) {
21+
let _images = images.slice(i, i + 1);
22+
23+
console.log('batch image start: ', i);
24+
25+
await Promise.all(
26+
_images.map(async (value, index, array) => {
27+
console.log('image start: ', index + i);
28+
await fetch(value).then((res) => res.text());
29+
console.log('image end: ', index + i);
30+
}),
31+
);
32+
33+
console.log('batch image end: ', i);
34+
}
35+
}, 0);
36+
},
37+
38+
sendByFive: (images) => {
39+
setTimeout(async () => {
40+
for (let i: number = 0; i < images.length; i += 5) {
41+
let _images = images.slice(i, i + 5);
42+
43+
console.log('batch image start: ', i);
44+
45+
await Promise.all(
46+
_images.map(async (value, index, array) => {
47+
console.log('image start: ', index + i);
48+
await fetch(value).then((res) => res.text());
49+
console.log('image end: ', index + i);
50+
}),
51+
);
52+
53+
console.log('batch image end: ', i);
54+
}
55+
}, 0);
56+
},
57+
};
58+
59+
requestOptions.sendByOne(images);
60+
requestOptions.sendByFive(images);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /