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

feat: add concurrentPool #306

Merged
merged 7 commits into from
Mar 2, 2025
Merged

feat: add concurrentPool #306

merged 7 commits into from
Mar 2, 2025

Conversation

ppeeou
Copy link
Member

@ppeeou ppeeou commented Feb 27, 2025

Fixes #304

I'd like to get feedback from you @ysm-dev
What do you think about the expression and behavior?

@ppeeou ppeeou self-assigned this Feb 27, 2025
@ppeeou ppeeou requested a review from hg-pyun February 27, 2025 16:37
@ppeeou ppeeou force-pushed the feat/concurrent-pool branch from 53cbcf3 to b19eece Compare February 27, 2025 16:39
Copy link
Collaborator

@hg-pyun hg-pyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the concurrentPool is same here code logic that written by @indongyoo. Referencing this code might be helpful.

Comment on lines 71 to 89
await chainItem(item);
} catch (error) {
idleWorkers++;
finished = true;

const item = {
success: { done: false },
fail: error,
} as Item<A>;

itemMap.set(id, item);
await chainItem(item);
}
}

async function chainItem(item: Item<A>) {
prev = prev.then(() => item).then(pullItem);
return item;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to use the async keyword if await is not used inside chainItem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't remove what I had previously declared. Thank you.

* @experimental concurrentPool
*/
function concurrentPool<A>(
length: number,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure if the name length clearly represents its role. Is this a common variable name in functions dealing with concurrency?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to match it with the variable name of concurrent.

When changing it, it would be better to proceed with the variable name of concurrent!
ex) concurrency?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

Copy link
Contributor

@ysm-dev ysm-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ppeeou ppeeou merged commit 47dd196 into main Mar 2, 2025
1 check passed
* map((a) => delay(100 * a, a)),
* concurrentPool(3),
* each(console.log), // log 1, 2, 3, 4, 5, 6
* ); // 2 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants