Comments (9)
It is now possible to resume generators with arguments. The generators implementing Processes must now accept resume arguments of type SimContext
. Calling it's time() method it is possible to know the elapsed simulation time.
from desim.
Looked into it again in depth. Introducing Rc
and RefCell
is not enough - a solution might be to introduce a Context
object and move the time to there.
My first attempt (unpolished): quantverse@59e4701
Modified example:
#![feature(generators, generator_trait)]
extern crate desim;
use desim::{Simulation, Effect, Event, EndCondition, Context};
use std::rc::Rc;
use std::cell::RefCell;
fn main() {
let ctx = Rc::new(RefCell::new(Context::new()));
let mut s = Simulation::new(ctx.clone());
let g = Box::new(move || {
let tik = 0.7;
loop{
println!("tik {}", ctx.borrow().time());
yield Effect::TimeOut(tik);
}
});
let p = s.create_process(g);
s.schedule_event(Event{time: 0.0, process: p});
let s = s.run(EndCondition::Time(10.0));
}
What do you think? I would really prefer a solution without using Rc
/Refcell
but not able to come with any (I am quite new to Rust)...
from desim.
I like the solution. Maybe the context could be Pin
ned, but it's new syntax and I am not sure whether it can be applied in this case
from desim.
It would be easier if it was possible to resume the generator with arguments, as the context could be passed by the simulation driver to the process at each resume.
from desim.
I like the solution. Maybe the context could be
Pin
ned, but it's new syntax and I am not sure whether it can be applied in this case
Thanks, I would still prefer to avoid using Rc
and RefCell
whatsoever, but no idea how to do it without it. All generators must capture a pointer or reference to the context, so the only option would be that Simulation methods all work with self
directly (claiming ownership). I don't like that idea much.
Why would you Pin
the context? I assumed that pinning is mostly useful for self-referential structs and generators only...here we use the reference counting / shared ownership to maintain the context...
It would be easier if it was possible to resume the generator with arguments, as the context could be passed by the simulation driver to the process at each resume.
That would be the best solution indeed, but that feature is still in the Pre-RFC state: https://internals.rust-lang.org/t/pre-rfc-generator-resume-args/10011
Unfortunately I have to start developing the simulation ASAP...
from desim.
Do you think we can follow the current implementation of the await!
macro as explained in that thread in order to update this later on, when the RFC will be stabilized?
from desim.
Honestly I don't really like the idea of using the await!
macro for this...I guess for the time being I will just use my hack, the proper idea really seems to wait for the generator resume arguments...
from desim.
I did not mean to use the await macro directly, but to use the same strategy used in that case. But I am not sure it is feasible.
from desim.
If you mean using the TLS like they do - I think it is more of a hack than a appropriate implementation...
from desim.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from desim.