WalletConnect / a2

An Asynchronous Apple Push Notification (apns2) Client for Rust
MIT License
136 stars 47 forks source link

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

Closed rajesh-blueshift closed 1 year ago

rajesh-blueshift commented 3 years ago

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 commented 3 years ago

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

rajesh-blueshift commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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