Asynchronous decoding
oovm opened this issue · 2 comments
I'm using an async callback here, which doesn't seem to support:
Or is this an anti-pattern?
error[E0308]: mismatched types
--> \src\session\server\text2image.rs:31:71
|
31 | cb: Box::new(|steps, timestamp, image| {
| _______________________________________________________________________-
32 | | for (index, image) in image.iter().enumerate() {
33 | | let png = match encode_png(image) {
34 | | Ok(png) => png,
... |
50 | | true
51 | | }),
| | ^
| | |
| |_____________________expected `bool`, found `async` closure body
| arguments to this function are incorrect
|
= note: expected type `bool`
found `async` closure body `[async closure body@src\session\server\text2image.rs:31:71: 51:22]`
note: function defined here
--> \core\src\future\mod.rs:123:14
|
123 | pub const fn identity_future<O, Fut: Future<Output = O>>(f: Fut) -> Fut {
| ^^^^^^^^^^^^^^^
In my usage scenario, the user renders the image by sending a request, and these operations are all asynchronous.
Or should I use the queue mode?
StableDiffusionPipeline
is only send data to the channel, and the server only receive the filled data.
I also have a related question about how to interrupt a render?
This can be done by setting the callback to false.
But it is unknown when the user will raise an interrupt.
I seem to build a TaskHandler for each Task, and then set the value to false when a cancellation request is received, and pass it to the next a callback?
There will still be a delay unless callback is 1.
Is there a better suggestion?
In my usage scenario, the user renders the image by sending a request, and these operations are all asynchronous.
Or should I use the queue mode?
StableDiffusionPipeline
is very synchronous, so yes, you should probably use channels or a queue system.
I seem to build a TaskHandler for each Task, and then set the value to false when a cancellation request is received, and pass it to the next a callback?
There will still be a delay unless callback is 1.
Is there a better suggestion?
Nope, that seems like the best solution.