# CoroutineScopePool

open class CoroutineScopePool(parentJobBuilder: () -> Job, commonExceptionHandler: CoroutineExceptionHandler, scopeDescriptors: List<CoroutineScopeDescriptor>, scopeComposer: (CoroutineScopeDescriptor, Job, CoroutineDispatcher) -> CoroutineScope = { descriptor, job, dispatcher -> CoroutineScope( descriptor + job + dispatcher + commonExceptionHandler ) }) : Closeable

Provides a handy functionality for coroutine scopes management.

## Description

Automates creation and cancellation of scopes.

Once CoroutineScope is created via scopeComposer, the scope is automatically being stored in scopeMap and subsequent Jobs are being added to Parent's one by calling CoroutineScope.launch.

Once close is called, all the scopes and resources are released. The instance can't be reused then.

### Responsibilities

- Scopes creation

- Graceful Scopes cancellation

> Cancellation: close function should be considered as a blocking, waiting till all dedicated resources close . It is IMPORTANT to await it's execution

#### See also

CoroutineScopePool.initializeScopeMap

#### Throws

IllegalStateException

if initializeScopeMap throws it

## Constructors

CoroutineScopePool
Link copied to clipboard
constructor(parentJobBuilder: () -> Job, commonExceptionHandler: CoroutineExceptionHandler, scopeDescriptors: List<CoroutineScopeDescriptor>, scopeComposer: (CoroutineScopeDescriptor, Job, CoroutineDispatcher) -> CoroutineScope = { descriptor, job, dispatcher -> CoroutineScope( descriptor + job + dispatcher + commonExceptionHandler ) })

## Functions

close
Link copied to clipboard
open override fun close()

Uses thread blocking, avoid usage on the Main thread of application.

get
Link copied to clipboard
operator fun get(descriptor: CoroutineScopeDescriptor): CoroutineScope