bevy_coroutine 0.4.0

A simple library to run coroutines in Bevy
Documentation
use bevy::prelude::*;
use bevy::ecs::system::{Adapt, AdapterSystem, RunSystemError};

/// Generates a system that executes the given system with the given input
pub fn with_input<S, I, O, M>(input: I, system: S) -> AdapterSystem<InputAdapter<I>, S::System>
where
	S: IntoSystem<In<I>, O, M>,
	I: Sync + Send + Clone + 'static,
{
	let system = IntoSystem::into_system(system);
	let name = format!("with_input({})", system.name());
	AdapterSystem::new(InputAdapter(input), system, name.into())
}

/// Used with [`AdapterSystem`] to pass an input to a system.
#[doc(hidden)]
pub struct InputAdapter<I>(I);

impl<'l, S> Adapt<S> for InputAdapter<SystemIn<'l, S>>
where
	S: System,
	SystemIn<'l, S>: Sync + Send + Clone + 'static,
{
	type In = ();
	type Out = S::Out;

	fn adapt(
		&mut self,
		_input: (),
		run_system: impl FnOnce(SystemIn<'_, S>) -> Result<S::Out, RunSystemError>,
	) -> Result<S::Out, RunSystemError>
	{
		run_system(self.0.clone())
	}
}