-
Notifications
You must be signed in to change notification settings - Fork 24
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
Async primitives #85
base: main
Are you sure you want to change the base?
Async primitives #85
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes ;D good work!
* @param value | ||
* the grant counter | ||
*/ | ||
class Semaphore private (private var value: AtomicInteger) extends Async.Source[Unit]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want this to be a Source
I think it's better to make it a source with a release value (a Source[SemGuard]
with a .release
method?) or maybe a Resource[Unit]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really want it to be a Source. But that's the only thing one can await, so I do need a Source implementation somehow. I could add it as hidden inner object or make Semaphore a trait and have the hidden implementation implement the Source, but both add (allocation/method lookup) overhead.
The SemGuard
idea looks nice, but then I would want the Semaphore
again to implement it as well, just returning this from the Source.
Using a Semaphore
as a Resource
is a good idea, but maybe not as the default interface.. ?
…urce.both and all
This PR contains primitives for synchronization and concurrency management:
Resource
to wrap allocation/cleanup of (currently mostly computation) resources in different layers of safetySemaphore
, because it's usefulAdditionally, the specification of
Async.await
in light of locking Sources, that care about there result being used (like Semaphores which the consumer might want to reset on cancellation), was clarified and implemented. Now, cancellation will be ignored if it happens after a listener lock acquire that leads to completion. Still, cancellation can be requested synchronously without waiting.