Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How about splitting the function definitions onto their own lines? I've also added parenthesis to make the function calls clearer (to me). </p> <pre><code>work = () -&gt; async.each( config.targets, (target, callback) -&gt; async.eachLimit( sitemaps, config.concurrency.sitemaps, (sitemap, callback) -&gt; async.eachLimit( sitemap, config.concurrency.urls, (url, callback) -&gt; async.eachSeries( config.requests, (req, callback) -&gt; doRequest( target, sitemap, url, req, callback) , callback) , callback) , callback) , (err) -&gt; console.log "All done" ) </code></pre> <p>EDIT</p> <p>In theory one or more of the inner loops could be broken out as named functions. For example:</p> <pre><code>foo1 = (sitemap, callback) -&gt; async.eachLimit( sitemap, config.concurrency.urls, (url, callback) -&gt; async.eachSeries( config.requests, (req, callback) -&gt; doRequest( target, sitemap, url, req, callback) , callback) , callback) work1 = () -&gt; async.each( config.targets, (target, callback) -&gt; async.eachLimit( sitemaps, config.concurrency.sitemaps, foo1 , callback) , (err) -&gt; console.log "All done" ) # error - target is not defined in doRequest(target...) </code></pre> <p>The problem here is that<code>target</code> as set by the <code>work1</code> loop, does not get passed through <code>foo1</code> to <code>doRequest</code>.</p> <p>Looks like <code>async.apply</code> can be used to get around this problem</p> <pre><code>foo2 = (target, sitemap, callback) -&gt; async.eachLimit( sitemap, config.concurrency.urls, (url, callback) -&gt; async.eachSeries( config.requests, (req, callback) -&gt; doRequest( target, sitemap, url, req, callback) , callback) , callback) work2 = () -&gt; async.each( config.targets, (target, callback) -&gt; async.eachLimit( sitemaps, config.concurrency.sitemaps, async.apply(foo2, target) , callback) , (err) -&gt; console.log "All done 2" ) </code></pre> <p>Or carrying this partitioning to its extreme:</p> <pre><code>foo1 = (target, callback) -&gt; async.eachLimit( sitemaps, config.concurrency.sitemaps , async.apply(foo2, target) , callback) foo2 = (target, sitemap, callback) -&gt; async.eachLimit( sitemap, config.concurrency.urls , async.apply(foo3, target, sitemap) , callback) foo3 = (target, sitemap, url, callback) -&gt; async.eachSeries( config.requests , async.apply(doRequest, target, sitemap, url) , callback) work3 = () -&gt; async.each(config.targets, foo1 , (err) -&gt; console.log "All done 3" ) </code></pre> <p>Other binding/partial methods would work</p> <pre><code>foo2.bind(null, target) # Javascript bind _.partial(foo2, target) # lodash, underscore </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload