-
Notifications
You must be signed in to change notification settings - Fork 64
[data][prelude][core] Poll effect + handleFirst #891
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
Conversation
@@ -0,0 +1,66 @@ | |||
package kyo |
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.
,oved to the kyo
package since it's shared between Emit
, Poll
, and Stream
.
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.
Cool effect! Will need to dive deeper to see how I can make use of it.
end apply | ||
end RunFirstOps | ||
|
||
inline def runFirst[V >: Nothing]: RunFirstOps[V] = RunFirstOps(()) |
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.
runHead
?
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'd prefer to keep a consistent naming with ArrowEffect.handleFirst
. The "first" is more about the first suspension than the first element.
* A computation that processes values until completion | ||
*/ | ||
def apply[S](f: V => Unit < S)(using tag: Tag[Poll[V]], frame: Frame): Unit < (Poll[V] & S) = | ||
Loop(()) { _ => |
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.
Should we add a apply0
? Followup is fine.
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 tried some time ago but had inference issues
ArrowEffect.handleFirst(emitTag, emit)( | ||
handle = [C] => | ||
(emitted, emitCont) => | ||
// Debug.values(emitted) |
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.
leftover?
ArrowEffect.handleFirst(pollTag, poll)( | ||
handle = [C2] => | ||
(ack, pollCont) => | ||
// Debug.values(ack) |
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.
leftover?
// 2. Pass the emitted value to poller for consumption | ||
// 3. Recursively continue the cycle | ||
Loop.continue(emitCont(ack), pollCont(Maybe(emitted))), | ||
8000 // Poll.run(emitCont(ack))(pollCont(Maybe(emitted))), |
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.
leftover?
Loop.continue(emitCont(ack), pollCont(Maybe(emitted))), | ||
// Poll.run(emitCont(ack))(pollCont(Maybe(emitted))), | ||
done = b => | ||
// Debug.values(b) |
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.
leftover?
* @return | ||
* The transformed computation result | ||
*/ | ||
inline def handleFirst[I[_], O[_], E <: ArrowEffect[I, O], A, B, S, S2](effectTag: Tag[E], v: A < (E & S))( |
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.
Effect handling is starting to get interesting!
Emit.runDiscard(emitCont(Ack.Stop)).map(a => Loop.done((a, b))) | ||
), | ||
done = a => | ||
// Debug.values(a) |
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.
leftover?
Co-authored-by: Adam Hearn <22334119+hearnadam@users.noreply.github.com>
Introduces a new
Poll
effect that functions as the opposite ofEmit
. I've also introducedArrowEffect.handleFirst
andEmit.handleFirst
, which might be useful for the work on Stream. I'm planning to usePoll
for anActor
implementation.