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

actix-rt: Provide custom tokio::runtime::Runtime #421

Closed
oblique opened this issue Nov 27, 2021 · 5 comments
Closed

actix-rt: Provide custom tokio::runtime::Runtime #421

oblique opened this issue Nov 27, 2021 · 5 comments

Comments

@oblique
Copy link

oblique commented Nov 27, 2021

Is there a way to provide a custom a tokio::runtime::Runtime? The only way I found is actix_rt::System::with_tokio_rt but it is hidden from documentation.

@robjtede
Copy link
Member

actix_rt::System::with_tokio_rt is the correct way to do this.

@oblique
Copy link
Author

oblique commented Nov 29, 2021

I don't want to rely on a hidden API. Is there a reason that is hidden? Can we have it as a non-hidden public API?

@robjtede
Copy link
Member

when actix-server comes out of beta, the hidden annotation will be removed. at this point it's very unlikely to change

@oblique
Copy link
Author

oblique commented Nov 29, 2021

Ok, thanks!

@robjtede robjtede mentioned this issue Dec 26, 2021
3 tasks
@robjtede robjtede closed this as completed Jan 4, 2022
@brandonros
Copy link

Brandons-MacBook-Air:diag-rust brandonros 2022-02-22 12:53:28 $ cargo build
   Compiling j2534-http-diag v0.0.1 (/Users/brandonros/Desktop/j2534-http/diag-rust)
warning: unused `#[macro_use]` import
 --> src/lib.rs:3:1
  |
3 | #[macro_use]
  | ^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `awc::Client`
  --> src/lib.rs:12:5
   |
12 | use awc::Client;
   |     ^^^^^^^^^^^

error[E0277]: `*const ()` cannot be sent between threads safely
  --> src/lib.rs:14:1
   |
14 | / lazy_static! {
15 | |   static ref runtime: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
16 | |   static ref system_tuner: Mutex<actix_rt::SystemRunner> = Mutex::new(actix_rt::System::with_tokio_rt(runtime));
17 | |   //static ref runtime_mutex: Mutex<tokio::runtime::Runtime> = Mutex::new(tokio::runtime::Runtime::new().unwrap());
18 | | }
   | |_^ `*const ()` cannot be sent between threads safely
   |
   = help: within `SystemRunner`, the trait `std::marker::Send` is not implemented for `*const ()`
   = note: required because it appears within the type `PhantomData<*const ()>`
   = note: required because it appears within the type `LocalSet`
   = note: required because it appears within the type `actix_rt::Runtime`
   = note: required because it appears within the type `SystemRunner`
   = note: required because of the requirements on the impl of `Sync` for `std::sync::Mutex<SystemRunner>`
note: required by a bound in `lazy_static::lazy::Lazy`
  --> /Users/brandonros/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/inline_lazy.rs:19:20
   |
19 | pub struct Lazy<T: Sync>(Cell<Option<T>>, Once);
   |                    ^^^^ required by this bound in `lazy_static::lazy::Lazy`
   = note: this error originates in the macro `__lazy_static_create` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
warning: `j2534-http-diag` (lib) generated 2 warnings
error: could not compile `j2534-http-diag` due to previous error; 2 warnings emitted
Brandons-MacBook-Air:diag-rust brandonros 2022-02-22 12:53:57 $ 
//#![cfg(windows)]

#[macro_use]
extern crate tokio;
extern crate winapi;
extern crate awc;
#[macro_use]
extern crate lazy_static;

use std::sync::Mutex;
use std::os::raw::{c_char, c_void};
use awc::Client;

lazy_static! {
  static ref runtime: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
  static ref system_tuner: Mutex<actix_rt::SystemRunner> = Mutex::new(actix_rt::System::with_tokio_rt(runtime));
  //static ref runtime_mutex: Mutex<tokio::runtime::Runtime> = Mutex::new(tokio::runtime::Runtime::new().unwrap());
}

Any recommendations on how to use actix_rt / tokio from a dylib/library/DLL context?

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

3 participants