On Tue, Aug 7, 2012 at 9:35 AM, Dan Milon <[email protected]> wrote:
> I am wondering which are the different patterns to handle cases like
>
>
> var results
> if (cond) {
> async1(function (err, res) {
> results = res
> })
> }
> else {
> async2(function (err, res) {
> results = res
> })
> }
> // here need to do something with results.
>
> The problem is obvious, but i cannot see any good way to overcome it.
It'll depend on the individual case, but what I'd probably do in the
specific case above is:
var asyncFn = cond ? async1 : async2
var results
asyncFn(function (err, res) {
// here need to do something with results.
})
--
Martin Cooper
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en