forked from lavina/lavina
1
0
Fork 0

add async-scoped

This commit is contained in:
Nikita Vilunov 2023-09-06 15:44:37 +02:00
parent 43ea27b655
commit fd96dd7449
4 changed files with 42 additions and 6 deletions

29
Cargo.lock generated
View File

@ -56,6 +56,18 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
[[package]]
name = "async-scoped"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e7a6a57c8aeb40da1ec037f5d455836852f7a57e69e1b1ad3d8f38ac1d6cadf"
dependencies = [
"futures",
"pin-project",
"slab",
"tokio",
]
[[package]]
name = "atoi"
version = "2.0.0"
@ -377,6 +389,21 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "futures"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.28"
@ -450,6 +477,7 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
@ -754,6 +782,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"assert_matches",
"async-scoped",
"derive_more",
"figment",
"futures-util",

View File

@ -25,6 +25,7 @@ quick-xml = { version = "0.30.0", features = ["async-tokio"] }
derive_more = "0.99.17"
uuid = { version = "1.3.0", features = ["v4"] }
sqlx = { version = "0.7.0-alpha.2", features = ["sqlite", "runtime-tokio-rustls", "migrate"] }
async-scoped = { version = "0.7.1", features = ["use-tokio"] }
[dev-dependencies]
assert_matches = "1.5.0"

View File

@ -57,7 +57,13 @@ async fn main() -> Result<()> {
let mut players = PlayerRegistry::empty(rooms.clone(), &mut metrics)?;
let telemetry_terminator =
util::telemetry::launch(telemetry_config, metrics.clone(), rooms.clone()).await?;
let irc = projections::irc::launch(irc_config, players.clone(), rooms.clone(), metrics.clone(), storage.clone()).await?;
unsafe { async_scoped::TokioScope::scope_and_collect(|s| {
s.spawn(async {
let irc = projections::irc::launch(&irc_config, &players, &rooms, &metrics, &storage).await?;
});
}) }.await;
let xmpp = projections::xmpp::launch(xmpp_config, players.clone(), rooms.clone(), metrics.clone()).await?;
tracing::info!("Started");

View File

@ -690,11 +690,11 @@ async fn produce_on_join_cmd_messages(
}
pub async fn launch(
config: ServerConfig,
players: PlayerRegistry,
rooms: RoomRegistry,
metrics: MetricsRegistry,
storage: Storage,
config: &ServerConfig,
players: &PlayerRegistry,
rooms: &RoomRegistry,
metrics: &MetricsRegistry,
storage: &Storage,
) -> Result<Terminator> {
log::info!("Starting IRC projection");
let (stopped_tx, mut stopped_rx) = channel(32);