pubnub-hyper 0.1.0

PubNub async crate based on Tokio and Hyper
Documentation

PubNub Hyper

A PubNub client using hyper and tokio to provide an ultra-fast, incredibly reliable message transport over the PubNub edge network.

Uses pubnub-core under the hood.

Example

use futures_util::stream::StreamExt;
use pubnub_hyper::runtime::tokio_global::TokioGlobal;
use pubnub_hyper::transport::hyper::Hyper;
use pubnub_hyper::{core::data::channel, core::json::object, Builder};

# async {
let transport = Hyper::new()
.publish_key("demo")
.subscribe_key("demo")
.build()?;
let mut pubnub = Builder::new()
.transport(transport)
.runtime(TokioGlobal)
.build();

let message = object! {
"username" => "JoeBob",
"content" => "Hello, world!",
};

let channel_name: channel::Name = "my-channel".parse().unwrap();
let mut stream = pubnub.subscribe(channel_name.clone()).await;
let timetoken = pubnub.publish(channel_name, message.clone()).await?;

let received = stream.next().await;
assert_eq!(received.unwrap().json, message);
# Ok::<(), Box<dyn std::error::Error>>(())
# };