pub async fn subscribe_account_diffs<F, Fut>(
rpc_endpoint: &str,
account: &str,
on_notification: F,
) -> Result<AccountDiffSubscriptionHandle, SubscriptionError>Expand description
Subscribe to account diff notifications and invoke a callback for each one.
Spawns a background task that:
- Connects to the WebSocket endpoint derived from
rpc_endpoint. - Subscribes to account diffs for the given filter (account or program).
- For each notification, spawns
on_notification(notification)as a Tokio task. - When
handle.stop.send(true)is called, drains remaining buffered notifications (up to 1s), waits for all spawned tasks, then returns.
ยงExample
use simulator_client::subscribe_account_diffs;
let handle = subscribe_account_diffs(
"http://localhost:8900/session/abc",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|notification| async move {
println!("slot={} sig={:?}", notification.context.slot, notification.signature);
},
)
.await?;
handle.stop.send(true).ok();
handle.join_handle.await.ok();