Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable fetcher immediate stop #1655

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/consumer/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ const createFetcher = ({
const start = async () => {
if (isRunning) return
isRunning = true
const stopPromise = new Promise(resolve => emitter.once('stop', resolve))

while (isRunning) {
try {
const batches = await fetch(nodeId)
const batches = await Promise.any([fetch(nodeId), stopPromise])
if (isRunning) {
const availableBatches = filterUnassignedBatches(batches)

Expand All @@ -77,7 +78,9 @@ const createFetcher = ({
const stop = async () => {
if (!isRunning) return
isRunning = false
await new Promise(resolve => emitter.once('end', () => resolve()))
const endPromise = new Promise(resolve => emitter.once('end', resolve))
emitter.emit('stop');
await endPromise;
}

return { start, stop, getWorkerQueue }
Expand Down
Loading