<commit_before>use neon::prelude::*;
use std::sync::{Mutex, MutexGuard};
use stencila::{
    once_cell::sync::{Lazy, OnceCell},
    pubsub, serde_json,
};

use crate::prelude::from_json;

pub struct JsSubscription {
    topic: String,
    subscriber: Root<JsFunction>,
}

static SUBSCRIPTIONS: Lazy<Mutex<Vec<JsSubscription>>> = Lazy::new(|| Mutex::new(Vec::new()));

/// The Neon event queue to which published events will be sent
static QUEUE: OnceCell<EventQueue> = OnceCell::new();

/// Obtain the subscriptions store
pub fn obtain(cx: &mut FunctionContext) -> NeonResult<MutexGuard<'static, Vec<JsSubscription>>> {<commit_msg>docs(Node.js): Add docs for pubsub module<commit_after>use crate::prelude::from_json;
use neon::prelude::*;
use std::sync::{Mutex, MutexGuard};
use stencila::{
    once_cell::sync::{Lazy, OnceCell},
    pubsub, serde_json,
};

/// The Neon event queue to which published events will be sent
static QUEUE: OnceCell<EventQueue> = OnceCell::new();

/// A JavaScript subscription
#[derive(Debug)]
pub struct JsSubscription {
    /// The topic that is subscribed to
    topic: String,

    /// The subscriber function
    subscriber: Root<JsFunction>,
}

/// A list of JavaScript subscriptions
static SUBSCRIPTIONS: Lazy<Mutex<Vec<JsSubscription>>> = Lazy::new(|| Mutex::new(Vec::new()));

/// Obtain the subscriptions store
pub fn obtain(cx: &mut FunctionContext) -> NeonResult<MutexGuard<'static, Vec<JsSubscription>>> {
{'fraction_non_alphanumeric': 0.14986187845303867, 'fraction_numerical': 0.0, 'mean_word_length': 5.497757847533633, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5479680', 'n_tokens_mistral': 459, 'n_tokens_neox': 473, 'n_words': 125}