4

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:

  1. get some ids,
  2. get items by id
  3. get relevant information for each items and attach those info to them
  4. 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)

1 Answer 1

15

Is there any recommendation for learning programming in async paradigm?

Try to look at these:

In order to prevent deeply nested callbacks in your code you can take advantage of several flow control node.js modules such as:

Sign up to request clarification or add additional context in comments.

2 Comments

Why you no recommend futuresJS
Thank you, the Control Flow in Node series help a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.