Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Tasks #37

Open
andre-di opened this issue Nov 23, 2023 · 0 comments
Open

Async Tasks #37

andre-di opened this issue Nov 23, 2023 · 0 comments

Comments

@andre-di
Copy link

Hi, I am trying to use AsyncScheduler within my project and I was just wondering if there were any better or more ergonomic ways of doing this? I struggled a lot getting the state shared, but somehow got that working. Any tips or tricks greatly appreciated.

pub async fn scheduler_init(state: Arc<State>) {
    let mut scheduler = AsyncScheduler::new();

    // Refactor these blocks into add function
    let shared_state = Arc::clone(&state);
    scheduler.every(60.seconds()).run(move || {
        let shared_state = Arc::clone(&shared_state);
        async move {
            test_task(&shared_state).await
        }
    });
    // endblock

    // Refactor these blocks into add function
    let shared_state = Arc::clone(&state);
    scheduler.every(60.seconds()).run(move || {
        let shared_state = Arc::clone(&shared_state);
        async move {
            test_task_two(&shared_state).await
        }
    });
    // endblock
}

async fn test_task_two(state: &Arc<State>)  {
    // do something
}

async fn test_task(state: &Arc<State>) {
    // do something
}

Thank you

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

No branches or pull requests

1 participant