Synchronous bracket for CLI bridge commands. Creates the best available watcher, enters `atomic-bridge` with the journaled operation ID, runs `body`, and leaves the state on success and failure alike. Writes performed inside the span are suppressed, so the bridge's own Git writes never trigger a self-reconciliation loop.
(
config: WatcherConfig,
operation_id: &str,
body: impl FnOnce() -> Result<T, E>,
)
| 74 | /// failure alike. Writes performed inside the span are suppressed, so the |
| 75 | /// bridge's own Git writes never trigger a self-reconciliation loop. |
| 76 | pub fn bracket_bridge_transaction<T, E>( |
| 77 | config: WatcherConfig, |
| 78 | operation_id: &str, |
| 79 | body: impl FnOnce() -> Result<T, E>, |
| 80 | ) -> Result<T, E> { |
| 81 | let runtime = match tokio::runtime::Builder::new_current_thread() |
| 82 | .enable_all() |
| 83 | .build() |
| 84 | { |
| 85 | Ok(runtime) => runtime, |
| 86 | Err(error) => { |
| 87 | log::warn!( |
| 88 | "could not create the atomic-bridge watcher runtime: {error}; \ |
| 89 | continuing without the optional accelerator" |
| 90 | ); |
| 91 | return body(); |
| 92 | } |
| 93 | }; |
| 94 | runtime.block_on(async { |
| 95 | let mut watcher = match create_watcher(config).await { |
| 96 | Ok(watcher) => watcher, |
| 97 | Err(error) => { |
| 98 | log::warn!( |
| 99 | "could not create the file watcher for atomic-bridge: {error}; \ |
| 100 | continuing without the optional accelerator" |
| 101 | ); |
| 102 | return body(); |
| 103 | } |
| 104 | }; |
| 105 | with_bridge_state(&mut *watcher, operation_id, async { body() }).await |
| 106 | }) |
| 107 | } |
| 108 | |
| 109 | /// Whether the given repo root can open a session-scoped watcher. |
| 110 | pub fn watcher_config(repo_root: &Path) -> WatcherConfig { |
no test coverage detected