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

Getting an issue with 'executor must be set' #55

Closed
rajesh-blueshift opened this issue Apr 19, 2021 · 4 comments · Fixed by #61
Closed

Getting an issue with 'executor must be set' #55

rajesh-blueshift opened this issue Apr 19, 2021 · 4 comments · Fixed by #61

Comments

@rajesh-blueshift
Copy link

rajesh-blueshift commented Apr 19, 2021

Hi I am new to Rust and still do not know about tokio. I am trying to run an example with certificates, but get this issue below:

thread 'main' panicked at 'executor must be set', /Users/rajesh/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.5/src/common/exec.rs:52:21
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.

Can you please help me with this?

@dbrgn
Copy link
Contributor

dbrgn commented Apr 19, 2021

It would probably help if you'd post your code.

@rajesh-blueshift
Copy link
Author

Here is the code:

use a2::{Client, Endpoint, NotificationBuilder, NotificationOptions, PlainNotificationBuilder};
use argparse::{ArgumentParser, Store, StoreOption, StoreTrue};
use pretty_env_logger;
use std::fs::File;
use tokio;

// An example client connectiong to APNs with a certificate and key
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    pretty_env_logger::init();

    let mut certificate_file = String::from("/Users/rajesh/Downloads/BlueshiftPushBluePkcs.p12");
    let mut password = String::from("blueshift");
    let mut device_token = String::from("860177d09c9a45900a20b1bf5de4eeddd4046b151bb837523d3218fdb135ead2");
    let mut message = String::from("Ch-check it out!");
    let mut sandbox = true;
    let mut topic: Option<String> = Some(String::from("com.blueshift.reads"));


    // Read the private key and certificate from the disk
    let mut certificate = File::open(certificate_file).unwrap();

    // Which service to call, test or production?
    let endpoint = if sandbox {
        Endpoint::Sandbox
    } else {
        Endpoint::Production
    };

    // Connecting to APNs using a client certificate
    let client = Client::certificate(&mut certificate, &password, endpoint).unwrap();

    let options = NotificationOptions {
        apns_topic: topic.as_ref().map(|s| &**s),
        ..Default::default()
    };

    // Notification payload
    let mut builder = PlainNotificationBuilder::new(message.as_ref());
    builder.set_sound("default");
    builder.set_badge(1u32);

    let payload = builder.build(device_token.as_ref(), options);
    println!("Sending payload");

    
    let response = client.send(payload).await?;

    println!("Sent: {:?}", response);

    Ok(())
}

@franklinvv
Copy link

franklinvv commented Apr 22, 2021

Using the example code on macOS to send a notification with token based authentication, I am getting the exact same error. I am trying with a2 v0.6.0 and have added tokio v1.5.0 as dependency. I am new to Rust as well.

The backtrace ends with the following:

    39: tokio::runtime::Runtime::block_on
         at /Users/franklin/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.5.0/src/runtime/mod.rs:452:43
    40: notifier::main
         at /Users/franklin/Developer/rust/Notifier/src/main.rs:9:1
    41: core::ops::function::FnOnce::call_once
         at /Users/franklin/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5

If I use a2 v0.5.3 and add tokio v0.2.25 as dependency, everything works fine.

@franklinvv
Copy link

Apparently, this is solved by enabling the runtime feature of the hyper dependency.

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 a pull request may close this issue.

3 participants