Comments (4)
QtPromise is used for promises in this library. The thread safety declaration is here: https://qtpromise.netlify.app/qtpromise/thread-safety.html
Fundamentally, I believe it relies on the Qt event loop which is thread safe if used correctly.
from httpserver.
Thanks Elliot. If could please show me the right method for processing heavy task with other module (such as ObjectDetection -OD- module - which run in other thread), without run qconcurrent for promise ( i cannot init this module alot of times, only one OD instance for whole project). Now, i can use async with timeout for send result. But it is not useful if processing time in OD is less or more than time out of task. Thank you very much!
from httpserver.
So, I'll provide a simplified example of what I do. I use HttpServer in a production application and I have blocking code that I run on a separate thread that is promisified.
Fundamentally, I want to point out this question is unrelated to this library however. Given that, I'm going to close this issue as well.
See the below Gist for an example of how you can do this: https://gist.github.com/addisonElliott/183f61b8594d294a5bb8d7b6486cf492
Note that this example won't work as-is. It's just meant to demonstrate the concept.
Details
- Qt's event loop is thread safe is used properly. So, I rely on that to communicate between the threads. Note that no data is shared between the threads except via the Qt event loop. Otherwise, it wouldn't be safe.
- WorkerThread is the class that starts the separate thread that processes various things. The main thread should initiate
WorkerThread
. - The
Worker
class has a list of slots that are executed on the separate thread. This is only meant to be used internally byWorkerThread
. - WorkerThread has the helper function
execAsyncPromise
that invokes a given slot in theWorker
class on the separate thread. WorkerThread::setControllersOffline()
- This function creates a promise that will execute the blocking function onWorker
Worker::setControllersOffline()
- This function is executed on the separate thread and can be blocking.
from httpserver.
Wow, thank you very much!
from httpserver.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpserver.