pipey 0.1.1

A lightweight HTTP-to-WebSocket event delivery service.
Documentation
#![allow(unused)]
//! Shared application state.
//!
//! This module defines state that is shared across request handlers.
use arifa::prelude::*;
use std::sync::Arc;

/// The shared application state type
#[derive(Clone)]
pub struct AppState {
    /// Individual server node ID
    pub node_id: String,
    pub arifa: Arc<Arifa>,
}

impl AppState {
    /// Create a new application state
    pub async fn new<T: Into<String>>(node_id: T, redis_url: &str) -> Self {
        let node_id: String = node_id.into();

        let arifa = Arc::new(
            Arifa::new(redis_url, &node_id)
                .await
                .expect("Failed to init Arifa"),
        );

        Self { node_id, arifa }
    }
}