Challenge: Control Parallelism in Async Tasks
Завдання
Swipe to start coding
Your goal is to implement an asynchronous method that processes a list of asynchronous tasks in parallel, while limiting the number of tasks that run at the same time.
- The method should accept two parameters:
- A list of asynchronous task factories (
Func<Task>), where each factory returns a task when invoked. - An integer representing the maximum number of concurrent operations (
maxDegreeOfParallelism).
- A list of asynchronous task factories (
- Ensure that at no point are more than
maxDegreeOfParallelismtasks running in parallel. - Every task factory in the list must be started and awaited, so that all tasks complete before the method returns.
- To control the number of concurrently running tasks, use a
SemaphoreSlim. Before starting a new task, callWaitAsyncon the semaphore to ensure you do not exceed the concurrency limit. After a task completes, callReleaseon the semaphore to allow another task to begin. - It is important to use
Task.WhenAllto await all started tasks, guaranteeing that the method does not return until every task has finished.
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 3. Розділ 4
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Чудово!
Completion показник покращився до 5.56
Challenge: Control Parallelism in Async Tasks
Свайпніть щоб показати меню
Завдання
Swipe to start coding
Your goal is to implement an asynchronous method that processes a list of asynchronous tasks in parallel, while limiting the number of tasks that run at the same time.
- The method should accept two parameters:
- A list of asynchronous task factories (
Func<Task>), where each factory returns a task when invoked. - An integer representing the maximum number of concurrent operations (
maxDegreeOfParallelism).
- A list of asynchronous task factories (
- Ensure that at no point are more than
maxDegreeOfParallelismtasks running in parallel. - Every task factory in the list must be started and awaited, so that all tasks complete before the method returns.
- To control the number of concurrently running tasks, use a
SemaphoreSlim. Before starting a new task, callWaitAsyncon the semaphore to ensure you do not exceed the concurrency limit. After a task completes, callReleaseon the semaphore to allow another task to begin. - It is important to use
Task.WhenAllto await all started tasks, guaranteeing that the method does not return until every task has finished.
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 3. Розділ 4
single