Skip to content

Events Settings are private? #3764

@thewrlck

Description

@thewrlck

Hi, I am trying to open_with_event_sender but settings from options are private.

Can someone help me?

use clap::Parser;
use ord::{
    settings::Settings,
    index::{event::Event, Index},
};
use std::{
    sync::atomic::{AtomicBool, Ordering},
    thread,
};

static SHUTDOWN_SIGNAL: AtomicBool = AtomicBool::new(false);

#[tokio::main]
async fn main() {
    println!("Starting custom ord indexer...");

    let index_options = Options::parse();
    let settings = Settings::from_options(index_options).or_defaults().unwrap();
    let (sender, mut receiver) = tokio::sync::mpsc::channel::<Event>(128);
    let index = Index::open_with_event_sender(&settings, Some(sender)).unwrap();

    // Handle Ctrl-C
    ctrlc::set_handler(move || {
        println!("Received Ctrl-C, shutting down...");
        SHUTDOWN_SIGNAL.store(true, Ordering::SeqCst);
    })
    .unwrap();

    let receiver_handle = tokio::spawn(async move {
        while !SHUTDOWN_SIGNAL.load(Ordering::SeqCst) {
            if let Some(event) = receiver.recv().await {
                match event {
                    Event::InscriptionCreated { .. } => {
                        println!("Inscription created: {:?}", event);
                    }
                    Event::InscriptionTransferred { .. } => {
                        println!("Inscription moved: {:?}", event);
                    }
                }
            }
        }
    });

    let index_handle = thread::spawn(move || loop {
        if SHUTDOWN_SIGNAL.load(Ordering::SeqCst) {
            break;
        }
        index.update().unwrap();
        thread::sleep(std::time::Duration::from_secs(3));
    });

    receiver_handle.await.unwrap();
    index_handle.join().unwrap();

    println!("Finished custom ord indexer.");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions