Since the event machine is called an event-based asynchronous I / O library (e.g. node.js), which is single-threaded and uses an event loop to process parallel requests, do you really need to take care and use (such as a rail controller when processing requests)?
I'm more used to the node.js model where you actually just complete your code inside a callback and then everything takes care of you. (the select () system call for kqueue, epoll, etc., which spawns new threads, is handled in the lower-level C ++ implementation), and ECMAscript, by its nature, has no threads anyway.
I recently saw this piece of ruby ββcode trying to learn about Event Machine:
Thread = Thread.current Thread.new{ EM.run{ thread.wakeup } }
I'm just wondering when threads should be used in the event-based programming paradigm in ruby ββand what specific situation will require us to use.
I know that Ruby has threads built into the language (MRI green threads, JRuby JVM threads), so it might be tempting to use threads? However, from my point of view, these are various defeats of the whole goal, if you really should not worry about them in the application code of a higher level, since an event-based model is used to solve this problem.
Thanks. evaluate any answers / clarifications.
source share