This does bring out another topic, when we need a call back? Any
rule ? In this case the function wii be replaced with a database one
later, so it might have some IO.


On Mar 10, 11:49 pm, Axel Kittenberger <axk...@gmail.com> wrote:
> If your user are not in a particular order, add to this: don't use an
> array if there is no order, but a hash (object).
>
> users = {};
>
> e.g. with adding a user by: users[id] = {|somenewuserdata|};
>
> In that case getting a new user is easy as:
>
> exports.get_user = function(id, func) {
>    func(users[id] ? null : "NOT_FOUND", users[id] || null);
>
> }
>
> I wonder, why you need a callback after all? Its not an IO operation
> with a delay. If not needed due to overall structure or so, it gets
> even simpler:
>
> exports.get_user = function(id) {
>    return users[id] || null;
>
>
>
>
>
>
>
> }

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to