How do I store javascript functions in a queue for them to be executed eventually [duplicate]

All functions are actually variables, so it’s actually pretty easy to store all your functions in array (by referencing them without the ()): // Create your functions, in a variety of manners… // (The second method is preferable, but I show the first for reference.) function fun1() { alert(“Message 1”); }; var fun2 = function() … Read more

d3.js v5 – Promise.all replaced d3.queue

You can simplify that code a lot: you don’t net to use new Promise with d3.json, since d3.json will itself create the promise. So, you can just do: var files = [“data1.json”, “data2.json”, “data3.json”]; var promises = []; files.forEach(function(url) { promises.push(d3.json(url)) }); Promise.all(promises).then(function(values) { console.log(values) }); Or, if you’re into the code golf, even shorter: … Read more

How do you pass a Queue reference to a function managed by pool.map_async()?

The following code seems to work: import multiprocessing, time def task(args): count = args[0] queue = args[1] for i in xrange(count): queue.put(“%d mississippi” % i) return “Done” def main(): manager = multiprocessing.Manager() q = manager.Queue() pool = multiprocessing.Pool() result = pool.map_async(task, [(x, q) for x in range(10)]) time.sleep(1) while not q.empty(): print q.get() print result.get() … Read more

How to iterate over a priority_queue?

priority_queue doesn’t allow iteration through all the members, presumably because it would be too easy in invalidate the priority ordering of the queue (by modifying the elements you traverse) or maybe it’s a “not my job” rationale. The official work-around is to use a vector instead and manage the priority-ness yourself with make_heap, push_heap and … Read more

How do I make and use a Queue in Objective-C?

Ben’s version is a stack instead of a queue, so i tweaked it a bit: NSMutableArray+QueueAdditions.h @interface NSMutableArray (QueueAdditions) – (id) dequeue; – (void) enqueue:(id)obj; @end NSMutableArray+QueueAdditions.m @implementation NSMutableArray (QueueAdditions) // Queues are first-in-first-out, so we remove objects from the head – (id) dequeue { // if ([self count] == 0) return nil; // to … Read more

awaitable Task based queue

I don’t know of a lock-free solution, but you can take a look at the new Dataflow library, part of the Async CTP. A simple BufferBlock<T> should suffice, e.g.: BufferBlock<int> buffer = new BufferBlock<int>(); Production and consumption are most easily done via extension methods on the dataflow block types. Production is as simple as: buffer.Post(13); … Read more