Skip to content

Injector update#167

Open
maciekglowka wants to merge 12 commits intomainfrom
event-injector
Open

Injector update#167
maciekglowka wants to merge 12 commits intomainfrom
event-injector

Conversation

@maciekglowka
Copy link
Copy Markdown
Contributor

Changes:

  • ModelInjector replaced by EventInjector
  • Injector can now inject queries as well

@maciekglowka maciekglowka requested a review from sbarral February 26, 2026 15:48

event_seq.push(fut);

let key = peek_next_key(&mut scheduler_queue, time);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbarral please note, here time is used (previously upper_time_bound was bound in the closure). Since we break on the key mismatch I think there is no logical change here. Please check however :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me :-)


event_seq.push(fut);

let key = peek_next_key(&mut scheduler_queue, time);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me :-)

///
/// If successsful returns a bool value indicating whether at least one item has
/// been spawned.
fn handle_scheduler_step(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write a comment here or maybe in the calling code just before the call to synchronize about the fact that dropping/consuming the scheduler (and injector) guards is necessary for correctness. This is subtle and could be lost in a future refactoring.

/// this model.
///
/// Event arguments are mapped to another type using the closure provided.
pub fn mapped_event_injector<F, C, T, U, S>(&self, func: F, map: C) -> EventInjector<T>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I just realize now that it would be better to have a consuming mapped method that transforms an Injector<T> into an Injector<U> because most frequently it is the user of the injector that will want to adapt it to its needs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already store a future in the event injector I had to use a bit of a matrioshka approach. (a side effect of this is that in theory user can stack the mappings if they wish).

/// specific deadline. A `ModelInjector` is always associated to a model
/// instance.
pub struct ModelInjector<M: Model> {
/// specific deadline. A `EventInjector` is always associated to a model
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A EventInjector" -> "An EventInjector"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}

/// Returns an injector associated to this model.
#[deprecated = "please use `event_injector` method instead"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"use" -> "use the"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

/// Returns an injector associated to this model.
#[deprecated = "please use `event_injector` method instead"]
#[allow(deprecated)]
pub fn injector(&self) -> ModelInjector<P::Model> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we hide all deprecated items in the docs perhaps with docs(hidden)? I don't know what is the general practice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think hiding is a good idea, since I do not think it has been used much (regardless of the common practice - if such exists)

/// If a stepping method such as
/// [`Simulation::step`](crate::simulation::Simulation::step) or
/// [`Simulation::run`](crate::simulation::Simulation::run) is executed
/// concurrently, the event will be processed at the deadline set by the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"event" -> "query"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants