DEV Community

loading...

Discussion on: Structured concurrency and pure functions

Collapse
iquardt profile image
Iven Marquardt

It is a Task based on continuations, that is merely a description of an async computation. However, when I actually invoke it, the async effect is unleashed and I am not in the pure realm of my application anymore. Why would I bother keeping it structural concurrent if I am already in an impure context?

This seems to be an interesting idea but I quite don't get it yet.

Thread Thread
adamw profile image
Adam Warski Author

I think purity isn't a binary property but can be considered in multiple contexts. Do you write to disk? Do you do network I/O? Do you print to the console? Do you rely on system time? Do you read env configuration? And finally - do you spawn threads?

Running an async Task might have side effects, but it's one thing if you know that once the task completes (you usually can schedule a callback or a subsequent computation when that happens) that some logging will happen, or that a network request will be sent (and complete!); it's another to have a runaway computation running concurrently, even though the calling one completed. That's the guarantee that structured concurrency can give you.

Thread Thread
iquardt profile image
Iven Marquardt

Agreed. Thanks for taking the time!

Forem Open with the Forem app