use tokio oneshot channel
This commit is contained in:
parent
cd3cb3aeb8
commit
215dc4cd13
1 changed files with 2 additions and 4 deletions
|
@ -153,8 +153,7 @@ impl Client {
|
||||||
&self,
|
&self,
|
||||||
request: reqwest_middleware::RequestBuilder,
|
request: reqwest_middleware::RequestBuilder,
|
||||||
) -> Result<ByteResponse, Error> {
|
) -> Result<ByteResponse, Error> {
|
||||||
// FIXME: is an entire channel per request overkill? maybe pool them?
|
let (sender, receiver) = tokio::sync::oneshot::channel();
|
||||||
let (sender, receiver) = async_channel::bounded(1);
|
|
||||||
|
|
||||||
// let tokio take care of the request + further json parsing
|
// let tokio take care of the request + further json parsing
|
||||||
// this is because reqwest doesn't like the glib main loop
|
// this is because reqwest doesn't like the glib main loop
|
||||||
|
@ -198,11 +197,10 @@ impl Client {
|
||||||
// note that in general its fine not to cancel the tokio task when its corresponding
|
// note that in general its fine not to cancel the tokio task when its corresponding
|
||||||
// mainloop task is dropped, since eg for song thumbnails there's already a semaphore
|
// mainloop task is dropped, since eg for song thumbnails there's already a semaphore
|
||||||
// limiting concurrent requests
|
// limiting concurrent requests
|
||||||
let _ = sender.send(perform(future.await).await).await;
|
let _ = sender.send(perform(future.await).await);
|
||||||
});
|
});
|
||||||
|
|
||||||
receiver
|
receiver
|
||||||
.recv()
|
|
||||||
.await
|
.await
|
||||||
.map_err(|_| Error::OtherError("failed to receive response from tokio loop"))?
|
.map_err(|_| Error::OtherError("failed to receive response from tokio loop"))?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue