Skip to content

Instantly share code, notes, and snippets.

@wpbrown
Created February 20, 2021 20:43
Show Gist options
  • Save wpbrown/d6f03d667c7fca659e15ad7092216827 to your computer and use it in GitHub Desktop.
Save wpbrown/d6f03d667c7fca659e15ad7092216827 to your computer and use it in GitHub Desktop.
original build_actors
async fn build_actors<'a, A, M, IM, B, BR>(
ctx: &BcContext<'_, Self>, models: IM, builder: B,
) -> HashMap<EntityId, Addr<A>>
where
BR: Future<Output = Result<A>>,
B: Fn(&M) -> BR,
IM: Iterator<Item = &'a M>,
M: 'a + Entity + EntityStatic,
A: Actor,
{
stream::iter(models)
.map(|m| {
let m = m;
let builder = &builder;
async move {
let maybe_actor = builder(m).await;
match maybe_actor {
Ok(actor) => match actor.start().await {
Ok(started_actor) => Some((m.id(), started_actor)),
Err(error) => {
logged_error(
ctx.log(),
error.context(format!(
"failed to start {} actor '{}'",
M::entity_type_static(),
m.name()
)),
);
None
}
},
Err(error) => {
logged_error(
ctx.log(),
error.context(format!(
"failed to create {} actor '{}",
M::entity_type_static(),
m.name()
)),
);
None
}
}
}
})
.buffer_unordered(16)
.filter_map(|r| future::ready(r))
.collect::<HashMap<_,_>>()
.await
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment