Repository navigation
Conversation
|
actually i wonder if returning receiver is the right choice, passing sender as argument might be better, but it'll be inconsistent with current api |
|
Actually I just completely understand what's wrong, it should be accepting a |
kapok-4o
left a comment
There was a problem hiding this comment.
- A one-shot closure is a good fit for completion. Could we call this
append_with_callbackand takeimpl FnOnce() + Send + 'staticwith no return value? The current signature makes callers box the closure and creates a channel even when they only want the callback.append_with_signalalready gives callers a receiver. (src/queue.rs:78,src/queue.rs:94) - Please document that the callback runs inline when the queue is pulled past the source's end. With device playback, this can run on the audio thread while samples are still buffered. The callback should return promptly and avoid blocking or panicking. Clearing a pending source or dropping the output before the callback runs skips it. (
src/queue.rs:90,src/queue.rs:124,src/queue.rs:280,src/stream.rs:536) - Please add a queue test that checks the callback fires once before the next source yields. Please also use
SourcesQueueInputin the changelog. (src/queue.rs:300,CHANGELOG.md:21)
|
|
I believe all issues raised have been fixed, remind me if there's any issue I need to fix. |
kapok-4o
left a comment
There was a problem hiding this comment.
Thanks for the quick update, the rename, the FnOnce() + Send + 'static bound, and the changelog fix (src/queue.rs:96, CHANGELOG.md:21).
- Please return
()and omit channel creation (src/queue.rs:96).Player::sleep_until_endalready gets its receiver throughappend_with_signal(src/player.rs:169). - Please document that polling past the source's end calls the callback inline, possibly on the audio thread while samples are still buffered. It should return promptly without blocking or panicking. Clearing the pending source or dropping the output before the call skips it (
src/queue.rs:90,src/queue.rs:123,src/queue.rs:279,src/stream.rs:536). - The test checks a flag after polling an empty source. Please queue two nonempty sources and check that the callback fires exactly once, before the second source yields (
src/queue.rs:513).
A Box<dyn FnOnce() + Send + 'static> implements FnOnce and can be passed directly. The extra allocation at enqueue time and extra indirection at completion seem fine for a one-shot callback (src/queue.rs:104, src/queue.rs:283).
Library tests pass with both channel implementations.
Aight, should be fixed. my brain was still thinking of the old implementation which is why I thought channel must be created 😂, sorry about the brainfart |
|
Actually, append_with_signal can use append_with_callback internally, unifying the implementation (and removes the need for the enum), but of course it doesn't offer any benefit for now and introduces extra indirection. I guess if in the future the method needs to be expanded with more lines it can be considered. |
kapok-4o
left a comment
There was a problem hiding this comment.
Thanks, this is close. The return type, the inline-callback docs and the enum all look good to me. Two small things left:
- Could the docs also say the callback is skipped if
clear()removes the pending source or the queue output is dropped before it runs (src/queue.rs:99,src/queue.rs:126,src/queue.rs:135)? - The test calls
go_next()twice and never reads a sample. Could it drive the queue withnext()and check the count is zero through the first source, already one when the second source yields its first sample, and still one after the queue is drained (src/queue.rs:232,src/queue.rs:530)?
Agreed that append_with_signal can keep using the channel directly (src/queue.rs:83).
I am not sure if I understand correctly what you meant, do you want to check if the callback is called if the final sample of first source is yielded or when the first sample of second source is yielded? It seems that the current behavior is latter so I will write test for that. |
|
Yes, the latter: by the time |
Done. Anything else to add? |
kapok-4o
left a comment
There was a problem hiding this comment.
Thanks for sticking with this. Looks good to me.
Two optional touches, not blocking:
- The note says the callback is skipped when
clear()is called, butclear()only drops pending sources, so the playing source's callback still runs (src/queue.rs:101,src/queue.rs:299). "if its source is removed byclear()before it plays" would be exact. - The test could assert the count is still 0 on each sample of the first source and 1 when
next()returnsSome(0.4), so an early callback would fail it (src/queue.rs:533).
Done 👍, I also added some docs to |
Add
SourcesQueueInput::append_with_callbackthat allows user to provideimpl FnOnce() + Sendas a callback.