Comments (6)
Here are some question:
q1: How to enter multiple parameters(task function)?
q2: How to enter dynamic parameters(task function)?
q3: How to enter input generic (data) parameters(task function)?
from delay-timer.
Describe the bug
add parameters to task function will get error of lifetime.run example s demo.r,
error[E0621]: explicit lifetime required in the type of `url` --> examples/demo.rs:81:10 | 81 | .spawn(body) | ^^^^^ lifetime `'static` required error[E0621]: explicit lifetime required in the type of `url` --> examples/demo.rs:68:16 | 68 | let body = create_async_fn_body!({ | ________________^ 69 | | if let Ok(mut res) = surf::get(url).await { 70 | | dbg!(res.body_string().await.unwrap_or_default()); 71 | | ... | 74 | | } 75 | | }); | |______^ lifetime `'static` required | = note: this error originates in the macro `create_async_fn_body` (in Nightly builds, run with -Z macro-backtrace for more info)
The correct way to write it is right here.
from delay-timer.
Here are some question:
q1: How to enter multiple parameters(task function)?
q2: How to enter dynamic parameters(task function)?
q3: How to enter input generic (data) parameters(task function)?
Hi friend, I'm here to answer your questions.
1 . the task input multiple environment variables can be achieved by another way of writing macros, the documentation can be found in this section of -README: Capture the specified environment information and build the closure & task
.
2.Because task is a metadata, it will continue to generate task instances in the run, the running task instances are Future state machine can not update variables, but can update Task task itself through DelayTimer::update_task
, task-id consistent can be.
- generic (data) parameters are the same way.
Why does Rust require your data to be static-lived?
Because the underlying task scheduler is an asynchronous runtime, and the runtime of each task is uncertain. The compiler must give the user the assurance that all variables are static for the program to execute safely.
from delay-timer.
great~
But there are still some questions about q3.
trait Animal {
fn call(&self);
}
struct Dog;
struct Cat;
impl Animal for Dog {
fn call(&self) {
println!("this is Dog");
}
}
impl Animal for Cat {
fn call(&self) {
println!("this is Cat");
}
}
// Generic Data Types(this is static dispatch)
// TODO: if Animal is parameter
fn generic_animal_call<T: Animal>(animal: T) {
animal.call();
}
// dynamic dispatch
fn dynamic_animal_call(animal: &dyn Animal) {
animal.call();
}
from delay-timer.
great~
But there are still some questions about q3.trait Animal { fn call(&self); } struct Dog; struct Cat; impl Animal for Dog { fn call(&self) { println!("this is Dog"); } } impl Animal for Cat { fn call(&self) { println!("this is Cat"); } } // Generic Data Types(this is static dispatch) // TODO: if Animal is parameter fn generic_animal_call<T: Animal>(animal: T) { animal.call(); } // dynamic dispatch fn dynamic_animal_call(animal: &dyn Animal) { animal.call(); }
Here is the case with the generic type, you can do anything with thread safety.
from delay-timer.
nice job !
from delay-timer.
Related Issues (20)
- cyclic package dependency once this package is enabled HOT 1
- delay_timer rebuilds every time. HOT 2
- examples/demo_async_std.rs run error when duration 30s HOT 2
- Add more details when error HOT 1
- Can not transmit args to shell HOT 2
- Many jobs sometimes HOT 18
- an error occurls when use delay-timer 0.10.0 HOT 3
- build error HOT 2
- How to complete this demo with delay-timer? HOT 2
- The Tokio runtime is supported internally by default HOT 1
- Scheduler running is not correct run in UTC/Local mode HOT 2
- How to set a microsecond interval for task HOT 3
- Run task delay for an hour in UTC mode HOT 6
- Set a daily 00:00:00 trigger task, from April 2 every day trigger time into 01::00:00 HOT 5
- "set_frequency_once" always execute immediately. HOT 3
- The lru:v0.6.6 has a security hole. HOT 1
- Feature request: `DelayTimer` check if ID is in use HOT 4
- set_frequency_repeated_by_cron_str cannot work HOT 1
- The TimerEvent::AppendTaskHandle event should always be sent before The TimerEvent::FinishTask event. HOT 3
- Request to add the task to be executed immediately after a delay
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 delay-timer.