hey all :wave: I'm currently familiarising myself ...
# arrow
m
hey all 👋 I'm currently familiarising myself with Arrow and now I'm wondering how one does control concurrency when using its high-level concurrency. It's great not having to care about these details when implementing business logic but at some point it would be nice to control for example the size of the thread pool. Can you recommend any resources that go into more depth on that topic?
c
The functions you write are
suspend
.
suspend
functions can only be called in
suspend
functions. Of course, we need to be able to call the first
suspend
function, and we do this on a
CoroutineScope
, which contains a
CoroutineContext
. The thread pool is configured as part of the
Dispatcher
, one of the configuration elements of
CoroutineContext
.
s
It’s important (ish) to distinguish between concurrency and parallelism. Suspend functions can add concurrency by splitting a computation into multiple sub-computations. Arrow’s
parMap
function has an optional parameter to limit the number of sub-computations to create, which might be something like what you’re looking for. But parallelism is not introduced until you actually run the function, and the level of parallelism is controlled by the
CoroutineDispatcher
.
Practically speaking the level of concurrency is an upper limit on the level of parallelism — i.e., if you only break the task into ten pieces, you can’t usefully increase the parallelism higher than ten simultaneous threads
m
good point 👍 indeed, I was thinking more about parallelism there. Just want to build a clearer picture in my head of when and how code will actually be running in the system when put together using these mechanisms. But these points already clarified a great part of that. Thank you both!