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 bae8688

Browse files
Fix code style
1 parent e06bae0 commit bae8688

File tree

7 files changed

+34
-15
lines changed

7 files changed

+34
-15
lines changed

‎JavaScript/1-channels.js‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,21 @@ const job = (task, next) => {
8181

8282
const queue = Queue.channels(3)
8383
.process(job)
84-
.done((err, res) => {
84+
.done((error, res) => {
85+
if (error) console.log(`Done with error: ${error}`);
8586
const { count } = queue;
8687
const waiting = queue.waiting.length;
8788
console.log(`Done: ${res.name}, count:${count}, waiting: ${waiting}`);
8889
})
89-
.success((res) => console.log(`Success: ${res.name}`))
90-
.failure((err) => console.log(`Failure: ${err}`))
91-
.drain(() => console.log('Queue drain'));
90+
.success((res) => {
91+
console.log(`Success: ${res.name}`);
92+
})
93+
.failure((err) => {
94+
console.log(`Failure: ${err}`);
95+
})
96+
.drain(() => {
97+
console.log('Queue drain');
98+
});
9299

93100
for (let i = 0; i < 10; i++) {
94101
queue.add({ name: `Task${i}`, interval: i * 1000 });

‎JavaScript/3-pause.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ const queue = Queue.channels(3)
144144
.wait(4000)
145145
.timeout(5000)
146146
.process(job)
147-
.success((task) => console.log(`Success: ${task.name}`))
148-
.failure((err, task) => console.log(`Failure: ${err} ${task.name}`))
147+
.success((task) => {
148+
console.log(`Success: ${task.name}`);
149+
})
150+
.failure((error, task) => {
151+
console.log(`Failure: ${error} ${task.name}`);
152+
})
149153
.pause();
150154

151155
for (let i = 0; i < 10; i++) {

‎JavaScript/4-priority.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,13 @@ const job = (task, next) => {
152152
const queue = Queue.channels(3)
153153
.process(job)
154154
.priority()
155-
.done((err, task) => console.log(`Done: ${task.name}`))
156-
.drain(() => console.log('Queue drain'));
155+
.done((error, task) => {
156+
if (error) console.error(error);
157+
console.log(`Done: ${task.name}`);
158+
})
159+
.drain(() => {
160+
console.log('Queue drain');
161+
});
157162

158163
for (let i = 0; i < 10; i++) {
159164
queue.add({ name: `Task${i}`, interval: 1000 }, i);

‎JavaScript/5-pipe.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ class Queue {
155155
const destination = Queue.channels(2)
156156
.wait(5000)
157157
.process((task, next) => next(null, { ...task, processed: true }))
158-
.done((err, task) => console.log({ task }));
158+
.done((error, task) => {
159+
if (error) console.error(error);
160+
console.log({ task });
161+
});
159162

160163
const source = Queue.channels(3)
161164
.timeout(4000)

‎JavaScript/6-promise.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class Queue {
2323
}
2424

2525
next() {
26-
const emptyChannels = this.concurrency - this.count;
26+
const emptyChannels = this.concurrency - this.count;
2727
let launchCount = Math.min(emptyChannels, this.waiting.length);
2828
while (launchCount-- > 0) {
2929
this.count++;
3030
const task = this.waiting.shift();
3131
this.onProcess(task)
3232
.then(
3333
(res) => void this.finish(null, res),
34-
(err) => void this.finish(err)
34+
(err) => void this.finish(err),
3535
)
3636
.finally(() => {
3737
this.count--;
@@ -91,7 +91,7 @@ const queue = Queue.channels(3)
9191
const { count } = queue;
9292
const waiting = queue.waiting.length;
9393
console.log(
94-
`Done | res: ${res}, err: ${err}, count:${count}, waiting: ${waiting}`
94+
`Done | res: ${res}, err: ${err}, count:${count}, waiting: ${waiting}`,
9595
);
9696
})
9797
// .success((res) => void console.log(`Success: ${res}`))

‎JavaScript/7-stream.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class QueueStream extends Readable {
1919
}
2020

2121
_read() {
22-
const emptyChannels = this.concurrency - this.count;
22+
const emptyChannels = this.concurrency - this.count;
2323
let launchCount = Math.min(emptyChannels, this.waiting.length);
2424
while (launchCount-- > 0) {
2525
this.count++;

‎JavaScript/8-pipeline.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class QueueStream extends Readable {
1919
}
2020

2121
_read() {
22-
const emptyChannels = this.concurrency - this.count;
22+
const emptyChannels = this.concurrency - this.count;
2323
let launchCount = Math.min(emptyChannels, this.waiting.length);
2424
while (launchCount-- > 0) {
2525
const task = this.waiting.shift();
@@ -62,7 +62,7 @@ const writable = new Writable({
6262
write(data, encoding, next) {
6363
console.log({ data });
6464
next();
65-
}
65+
},
6666
});
6767

6868
const job = (task, next) => {

0 commit comments

Comments
(0)

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