aboutsummaryrefslogtreecommitdiff
path: root/src/assets.rs
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <[email protected]>2024-09-09 21:14:56 -0400
committerLibravatar Silas Bartha <[email protected]>2024-09-09 21:14:56 -0400
commit128573aa260644424e834e04ac08dd236736bf5d (patch)
treedb0b342fde17630947a4be04aef04bf99c0e5a4d /src/assets.rs
parent40fa831b47f14d649795faeced9cb8a59916f88f (diff)
Drop task with decoder
Diffstat (limited to 'src/assets.rs')
-rw-r--r--src/assets.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/assets.rs b/src/assets.rs
index 58a6ed3..5f0e08b 100644
--- a/src/assets.rs
+++ b/src/assets.rs
@@ -8,7 +8,7 @@ use bevy::{
asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext},
audio::Source,
prelude::*,
- tasks::AsyncComputeTaskPool,
+ tasks::{AsyncComputeTaskPool, Task},
};
use itertools::Itertools;
use rustysynth::{MidiFile, MidiFileSequencer, SoundFont, Synthesizer, SynthesizerSettings};
@@ -47,6 +47,7 @@ impl AssetLoader for MidiAssetLoader {
pub struct MidiDecoder {
sample_rate: usize,
stream: Receiver<f32>,
+ _task: Task<()>,
}
impl MidiDecoder {
@@ -58,7 +59,7 @@ impl MidiDecoder {
let mut midi = Cursor::new(midi);
let sample_rate = 44100_usize;
let (tx, rx) = async_channel::bounded::<f32>(sample_rate * 2);
- AsyncComputeTaskPool::get()
+ let task = AsyncComputeTaskPool::get()
.spawn(async move {
let midi = Arc::new(MidiFile::new(&mut midi).expect("Failed to read midi file."));
let settings = SynthesizerSettings::new(sample_rate as i32);
@@ -78,9 +79,9 @@ impl MidiDecoder {
}
}
tx.close();
- })
- .detach();
+ });
Self {
+ _task: task,
sample_rate,
stream: rx,
}