Beispiel #1
0
void producer(){
    std::chrono::milliseconds dura(0);
    string s("load");
    //auto shs = std::make_shared<string>(s);
    for(int i = 0; i < 15000; i++){
        //auto shs = std::make_shared<string>(string_format("%s%d\n",s.c_str() ,a++));
        auto shs = std::make_shared<string>("load" + to_string(i) + "\n");
        q.Dispatch(shs);
        if ((i % 150) == 0)
            std::this_thread::sleep_for( dura );

    }
}
    void Dispatch(const Type& event)
    {
        // Find the dispatcher for this event type.
        auto it = m_dispatchers.find(typeid(Type));

        if(it == m_dispatchers.end())
            return;

        // Cast the pointer that we already know is a dispatcher.
        Dispatcher<Type>* dispatcher = reinterpret_cast<Dispatcher<Type>*>(it->second.get());

        // Dispatch event to all receivers.
        dispatcher->Dispatch(event);
    }