All we need is an easy explanation of the problem, so here it is.
How to translate the following sync pseudo code into async js code
result = []
for pid in r.smembers('active_prog'):
for prog_obj in r.hgetall("prog:" + pid):
for item_obj in r.hgetall("item:" + prog_obj['iid']):
prog_obj['items'].append(item_obj)
result.append(prog_obj)
return result
That’s seems natural in sync programming:
- get some ids,
- get items by id
- get relevant information for each items and attach those info to them
- merge all items into an array and return
I’ve tried using MULTI but it seem doesn’t work when the recursion goes deeper.
Is there any recommendation for learning programming in async paradigm?(preferably in js code rather than .net stuff)
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
Is there any recommendation for learning programming in async
paradigm?
Try to look at these:
- Understanding Event-driven Programming
- Asynchronous iteration patterns in Node.js
- Tim Caswell’s PDF from jsConf
- How to stop writing spaghetti code
- Callbacks, synchronous and asynchronous
- The Step of the Conductor
- Control Flow in Node
- Control Flow in Node Part II
- Control Flow in Node Part III
In order to prevent deeply nested callbacks in your code you can take advantage of several flow control node.js modules such as:
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0