event-loop

How to integrate Boost.Asio main loop in GUI framework like Qt4 or GTK

喜夏-厌秋 提交于 2019-11-28 03:50:39
Is there any way to integrate Boost.Asio with Qt4 (preferred) or GTK main loop? GTK provides poll(2) like API so technically is should be possible. Qt provides its own networking layer, however I prefer to use existing code written for Boost.Asio. I want to integrate them without using an additional thread. Is there any reference how to do this for Qt4 (preferred) or GTKmm? Thanks. Edit I want to clearify several things to make the answer easier. Both Qt and GTKmm provide "select like" functionality: http://qt-project.org/doc/qt-5.0/qtcore/qsocketnotifier.html http://www.gtkmm.org/docs/glibmm

Grab user input asynchronously and pass to an Event loop in python

我们两清 提交于 2019-11-28 03:25:30
问题 I am building a single player MUD, which is basically a text-based combat game. It is not networked. I don't understand how to gather user commands and pass them into my event loop asynchronously. The player needs to be able to enter commands at any time as game events are firing. So pausing the process by using raw_input won't work. I think I need to do something like select.select and use threads. In the example below, I have a mockup function of userInputListener() which is where I like to

Why setImmediate() execute before fs.readFile() in Nodejs Event Loop's works?

天大地大妈咪最大 提交于 2019-11-27 22:33:18
I have read a lot of related documents.But I still can't understand how it works. const fs = require('fs') const now = Date.now(); setTimeout(() => console.log('timer'), 10); fs.readFile(__filename, () => console.log('readfile')); setImmediate(() => console.log('immediate')); while(Date.now() - now < 1000) { } const now = Date.now(); setImmediate(() => console.log('immediate')); setTimeout(() => console.log('timer'), 10); while(Date.now() - now < 1000) { } I think the first piece of code should log: readfile immediate And the second piece of code logs. timer immediate I think it is ok. Problem

Qt event loop and unit testing?

▼魔方 西西 提交于 2019-11-27 17:17:08
问题 I'we started experimenting with unit testing in Qt and would like to hear comments on a scenario that involves unit testing signals and slots. Here is an example: The code i would like to test is (m_socket is a pointer to QTcpSocket ): void CommunicationProtocol::connectToCamera() { m_socket->connectToHost(m_cameraIp,m_port); } Since that is an asynchronous call i can't test a returned value. I would however like to test if the response signal that the socket emits on a successful connection

How would you implement a basic event-loop?

元气小坏坏 提交于 2019-11-27 10:04:58
If you have worked with gui toolkits, you know that there is a event-loop/main-loop that should be executed after everything is done, and that will keep the application alive and responsive to different events. For example, for Qt, you would do this in main(): int main() { QApplication app(argc, argv); // init code return app.exec(); } Which in this case, app.exec() is the application's main-loop. The obvious way to implement this kind of loop would be: void exec() { while (1) { process_events(); // create a thread for each new event (possibly?) } } But this caps the CPU to 100% and is

What is the difference between “event loop queue” and “job queue”?

烈酒焚心 提交于 2019-11-27 08:03:56
I can not understand how the following code run. Why "1" is after "b" but "h" is after "3"? Should'n the order is: a, b, 1, 2, h, 3? Some article said that the difference between "event loop queue" and "job queue" leads to following output. But how? I have read the specification of ECMAScript 2015 - 8.4 Jobs and Job Queues , wanting to know how Promise'job works, but it makes me more confused. Can someone help me? Thank you! var promise = new Promise(function(resolve, reject) {resolve(1)}); promise.then(function(resolve) {console.log(1)}); console.log('a'); promise.then(function(resolve)

asyncio: Is it possible to cancel a future been run by an Executor?

混江龙づ霸主 提交于 2019-11-27 05:25:15
I would like to start a blocking function in an Executor using the asyncio call loop.run_in_executor and then cancel it later, but that doesn't seem to be working for me. Here is the code: import asyncio import time from concurrent.futures import ThreadPoolExecutor def blocking_func(seconds_to_block): for i in range(seconds_to_block): print('blocking {}/{}'.format(i, seconds_to_block)) time.sleep(1) print('done blocking {}'.format(seconds_to_block)) @asyncio.coroutine def non_blocking_func(seconds): for i in range(seconds): print('yielding {}/{}'.format(i, seconds)) yield from asyncio.sleep(1)

How to integrate Boost.Asio main loop in GUI framework like Qt4 or GTK

寵の児 提交于 2019-11-27 05:13:08
问题 Is there any way to integrate Boost.Asio with Qt4 (preferred) or GTK main loop? GTK provides poll(2) like API so technically is should be possible. Qt provides its own networking layer, however I prefer to use existing code written for Boost.Asio. I want to integrate them without using an additional thread. Is there any reference how to do this for Qt4 (preferred) or GTKmm? Thanks. Edit I want to clearify several things to make the answer easier. Both Qt and GTKmm provide "select like"

Why setImmediate() execute before fs.readFile() in Nodejs Event Loop's works?

送分小仙女□ 提交于 2019-11-26 21:01:59
问题 I have read a lot of related documents.But I still can't understand how it works. const fs = require('fs') const now = Date.now(); setTimeout(() => console.log('timer'), 10); fs.readFile(__filename, () => console.log('readfile')); setImmediate(() => console.log('immediate')); while(Date.now() - now < 1000) { } const now = Date.now(); setImmediate(() => console.log('immediate')); setTimeout(() => console.log('timer'), 10); while(Date.now() - now < 1000) { } I think the first piece of code

How can I detect a hang in QEventLoop?

孤人 提交于 2019-11-26 16:29:18
问题 I am not sure if the title of my question is formulated correctly, so to explain what I really mean, consider the following example: I create a QApplication and a QWidget with a QPushButton on it. Then I attach a handler to the click signal from the button that looks like this: void MyWidget::on_pushButton_clicked(){ //Never return while(true); } Finally I start the event loop for the application and when I run the program and the window shows up click the button. This will in my case stall