Giter VIP home page Giter VIP logo

Comments (4)

ArthurSonzogni avatar ArthurSonzogni commented on May 18, 2024

Thanks!

screen.PostEvent(Event::Custom);

is thread safe and will request a new frame to be drawn on the thread calling screen.Loop().

So I believe what you did works. Could you help me figure out what doesn't work?

Here is an example I built yesterday:
SAtacker/bb-config#7
that you might want to look. Threads aren't easy to deals with, I am exposing the Receiver/Sender utility class that FTXUI uses internally:
https://github.com/ArthurSonzogni/FTXUI/blob/master/include/ftxui/component/receiver.hpp

from ftxui.

JourneyToSilius avatar JourneyToSilius commented on May 18, 2024

yeah ! this is kind of what I am trying now, after reading about the receiver component , just a simple test :

void recv_msg(ftxui::Sender<std::wstring> &sender_1)
{

    KlineUtils kutils;

    sequence candle_sequence;

    string interval = "1m";

    string socket_address = "ipc:///home/xavier/ftxtui/" + interval;

    zmq::context_t ctx;

    zmq::socket_t socket(ctx, zmq::socket_type::pull);

    socket.bind(socket_address);

    while (true)
    {

        zmq::message_t message;

        socket.recv(message);

        string message_str = message.to_string();

        nlohmann::json j = nlohmann::json::parse(message_str);

        cout << j[299]["c"] << endl;

        std::string s = j[299]["c"].dump();

        std::wstring w = LR"(CURRENT PRICE: )" + fs::path(s).wstring();

        sender_1->Send(w);

        cout << "sender sent" << endl;


    }
}

void proc_received(Receiver<std::wstring> &receiver){

    std::vector<std::wstring> received;

    while (receiver->HasPending()) {
      std::wstring str;
      receiver->Receive(&str);
      received.push_back(str);
    }

    for ( auto v : received){
        cout << &v << endl;
    }

}

int main(int argc, const char *argv[])
{

    Receiver<std::wstring> receiver = MakeReceiver<std::wstring>();

    ftxui::Sender<std::wstring> sender_1 = receiver->MakeSender();

    thread t1;
    t1 = thread(recv_msg,ref(sender_1));
    thread t2;
    t2 = thread(proc_received, ref(receiver));
    t1.join();
    t2.join();

The thread where the receiver should be ? receiving and pushing to the vector from the sender doesn't print anything, meaning the while loop is not fiding any pending messages to be delivered ? Thanks !

from ftxui.

ArthurSonzogni avatar ArthurSonzogni commented on May 18, 2024

If thread2 is quick enough, (receiver->HasPending()) will be false, explaining what you are seeing.

What happen if you use:

    while (true) {
      std::wstring str;
      receiver->Receive(&str);
      std::cerr << "received: " << str << std::endl;
    }
}

Also, please pass sender_1 ownership by move. Don't use ref(sender_1). Same for receiver.

from ftxui.

JourneyToSilius avatar JourneyToSilius commented on May 18, 2024

Ok yes it makes total sense ! Now I'm getting the messages delivered, I will try to implement a screen and to update it, thanks !

from ftxui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.