3 ms·
The solution to all of this is incredibly simple but for some reason very few people seem to utilize it: State machines.
by jschrf 14y ago
The solution to all of this is incredibly simple but for some reason very few people seem to utilize it: State machines.
- pjscott 14y agoThe reason people don't use explicit state machines more is because it's kind of a painful way to write code. Suppose that I want to do a bunch of HTTP GETs, munge the data, and then fire off corresponding HTTP PUTs. I would like to be able to write something like: def process(job): http.put(job.destUrl, munge(http.get(job.srcUrl))) print "Processing some jobs" workerPool(MAX_CONNECTIONS).map(process, jobs) print "All done!" Wouldn't that be great? And in fact, you can do this easily with something like Eventlet, so I'm not asking too much here.
- spartango 14y agoAmusingly, in an environment with a level of parallelism, the above code poses few problems even if http.get/put are synchronous & blocking. A scheduler handles a bunch of blocked threads perfectly fine, and the series of calls per job aren't inefficient when executed in series. We hit pain points when we can't have parallelism in our programs, and are forced to make elegant the work-arounds intended to unclog those programs.