Skip to content

Commit

Permalink
♻️ rewrite section
Browse files Browse the repository at this point in the history
A section was placed in a nested scope. This allowed us to remove two
calls to `std::mem::drop()`.
  • Loading branch information
rneswold committed Aug 14, 2024
1 parent e205b39 commit f88d402
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions drmemd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,37 +156,34 @@ async fn run() -> Result<()> {
}
}

// Start the time-of-day task. This needs to be done *before*
// any logic blocks are started because logic blocks *may*
// have an expression that uses the time-of-day.
// Create a nested scope so that the tod and solar handles are
// freed up.

let (tx_tod, rx_tod) = logic::tod::create_task();

// Start the solar task. This, too, needs to be done before
// any logic blocks are started.
{
// Start the time-of-day task. This needs to be done
// *before* any logic blocks are started because logic
// blocks *may* have an expression that uses the
// time-of-day.

let (tx_solar, rx_solar) =
logic::solar::create_task(cfg.latitude, cfg.longitude);
let (tx_tod, _) = logic::tod::create_task();

// Iterate through the [[logic]] sections of the config.
// Start the solar task. This, too, needs to be done
// before any logic blocks are started.

for logic in cfg.logic {
tasks.push(wrap_task(logic::Node::start(
tx_clnt_req.clone(),
tx_tod.subscribe(),
tx_solar.subscribe(),
logic,
)));
}
let (tx_solar, _) =
logic::solar::create_task(cfg.latitude, cfg.longitude);

// Now that we've given all the logic blocks receive handles
// for the time-of-day and solar tasks, we can free up our
// copy. If we freed up our copy *before* creating new
// subscriptions, the tod or solar task may have briefly seen
// no clients and would exit.
// Iterate through the [[logic]] sections of the config.

std::mem::drop(rx_tod);
std::mem::drop(rx_solar);
for logic in cfg.logic {
tasks.push(wrap_task(logic::Node::start(
tx_clnt_req.clone(),
tx_tod.subscribe(),
tx_solar.subscribe(),
logic,
)));
}
}

// Now run all the tasks.

Expand Down

0 comments on commit f88d402

Please sign in to comment.