-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
priority: mediumShould be done soon but not blockingShould be done soon but not blockingstatus: needs discussionRequires team input before implementationRequires team input before implementationtype: enhancementImprovement to existing functionalityImprovement to existing functionality
Description
The problem currently is that it is easy to forget to call scanner.start() before starting to read the event stream.
This could be addressed using a sort of typestate pattern (open for discussion, need your input @LeoPatOZ ):
scanner.start()returns some structScannerStartedTokenthat cannot be instantiated outside the cratescanner.subscribe(filter)returnsSubscription- stream can only be accessed by passing the
ScannerStartedTokenlike:subscription.stream(scanner_started_token) - this ensures that
scanner.start()must be called before streaming can start
Full example:
// init scanner as before
let mut scanner = EventScannerBuilder::sync().from_block(0).connect(provider);
let filter = EventFilter::new();
// create subscription
let subscription = scanner.subscribe(filter);
// because scanner wasn't started, client can't access stream events yet
// let mut stream = subscription.stream(!!!missing token - won't compile!!!);
// start scanner
// name `token` used for simplicity, exact name open for discussion
let token = scanner.start().await?;
// now we're sure scanner is started, we can access the stream
let mut stream = subscription.stream(&token);
while let Some(msg) = stream.next().await {
// ...
}Metadata
Metadata
Assignees
Labels
priority: mediumShould be done soon but not blockingShould be done soon but not blockingstatus: needs discussionRequires team input before implementationRequires team input before implementationtype: enhancementImprovement to existing functionalityImprovement to existing functionality