Tabnine Logo For Javascript
async
Code IndexAdd Tabnine to your IDE (free)

How to use async

Best JavaScript code snippets using async(Showing top 15 results out of 3,114)

origin: clinicjs/node-clinic

function clean (dir, cb) {
 fs.readdir(dir, function (err, entries) {
  if (err) return cb(err)

  const pathsToRemove = entries
   .filter(entry => /^(\.clinic|\d+\.clinic-\w+(\.html)?|node_trace\.\d+\.log)$/.test(entry))
   .map(entry => path.join(dir, entry))

  async.eachSeries(
   pathsToRemove,
   (entry, next) => rimraf(entry, { disableGlob: true }, next),
   cb
  )
 })
}
origin: stdlib/lib

// Run everything in parallel...
   async.parallel(data.map((file) => {
    return (callback) => {
     pack.entry({name: file.filename}, file.buffer, () => {
      packSize += file.buffer.byteLength;
      progress.log(`Packing "${file.filename}" (${((packSize / data._size) * 100).toFixed(2)}%) ...`);
      callback();
     });
    };
   }), (err) => {
    if (err) {
     return reject(err);
    }
    pack.finalize();
   });
origin: clinicjs/node-clinic

test('clinic flame --name', function (t) {
 // collect data
 cli({ relayStderr: false }, [
  'clinic', 'flame', '--no-open', '--name', 'custom-name',
  '--', 'node', '-e', 'setTimeout(() => {}, 300)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)

  const htmlFilename = stdout.match(/(\d+\.custom-name)/)[1]
  const dirname = path.dirname(htmlFilename)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, htmlFilename), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: stdlib/lib

async.series(fns, (err) => {
origin: clinicjs/node-clinic

test('clinic flame -- node - no issues', function (t) {
 // collect data
 cli({}, [
  'clinic', 'flame', '--no-open',
  '--', 'node', '-e', 'require("util").inspect(process)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-flame)/)[1]
  const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

  t.strictEqual(stdout.split('\n')[1], 'Analysing data')
  t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, dirname + '.html'), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

async.parallel({
 createEmptyDirectory (done) {
  fs.mkdir(path.dirname(emptyDataDirectory), function (err) {
   if (err && err.code !== 'EEXIST') return done(err)
   fs.mkdir(emptyDataDirectory, function (err) {
    if (err && err.code !== 'EEXIST') return done(err)
    return done(null)
   })
  })
origin: clinicjs/node-clinic

async.parallel({
 createBigFile (done) {
  const bigFilepath = path.resolve(bigFileDirectory, 'big-file.tmp')
   if (st && st.size === bigFilesize) return done(null)
   fs.writeFile(bigFilepath, crypto.randomBytes(bigFilesize), done)
  })
origin: clinicjs/node-clinic

test('clinic flame --output-html', function (t) {
 // collect data
 cli({ relayStderr: false }, [
  'clinic', 'flame', '--no-open', '--output-html', '{name}-{pid}-{timestamp}.html',
  '--', 'node', '-e', 'setTimeout(() => {}, 300)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const match = stderr.match(/\/(clinic-flame-)(\d+)(-)(\d+)(\.html)/)
  const htmlFilename = match.slice(1).join('')
  const pid = match[2]
  const dirname = path.join(path.dirname(htmlFilename), pid + '.clinic-flame')

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, htmlFilename), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

test('clinic flame -- node - no issues', function (t) {
 // collect data
 cli({ relayStderr: false }, [
  'clinic', 'flame', '--no-open',
  '--', 'node', '-e', 'setTimeout(() => {}, 300)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)

  const htmlFilename = stdout.match(/(\d+\.clinic-flame\.html)/)[1]
  const dirname = path.dirname(htmlFilename)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, htmlFilename), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

test('clinic bubbleprof -- node - bad status code', function (t) {
 // collect data
 cli({ relayStderr: false }, [
  'clinic', 'bubbleprof', '--no-open',
  '--', 'node', '-e', 'process.exit(1)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-bubbleprof)/)[1]
  const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

  t.strictEqual(stdout.split('\n')[1], 'Analysing data')
  t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, dirname + '.html'), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

test('clinic doctor -- node - bad status code', function (t) {
 // collect data
 cli({ relayStderr: false }, [
  'clinic', 'doctor', '--no-open',
  '--', 'node', '-e', 'setTimeout(() => { process.exit(1) }, 400)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-doctor)/)[1]
  const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

  t.strictEqual(stdout.split('\n')[1], 'Analysing data')
  t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, dirname + '.html'), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

test('clinic flame --output-dir', function (t) {
 // collect data
 cli({ relayStderr: false }, [
  'clinic', 'flame', '--no-open', '--output-dir', '{name}-{pid}',
  '--', 'node', '-e', 'setTimeout(() => {}, 300)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const match = stderr.match(/\/(\d+)(\.)(clinic-flame)(\.html)/)
  const htmlFilename = match.slice(1).join('')
  const pid = match[1]
  const dirname = path.join(path.dirname(htmlFilename), 'clinic-flame-' + pid)
  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, htmlFilename), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

test('clinic flame -- node - bad status code', function (t) {
 // collect data
 cli({ relayStderr: false }, [
  'clinic', 'flame', '--no-open',
  '--', 'node', '-e', 'process.exit(1)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-flame)/)[1]
  const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

  t.strictEqual(stdout.split('\n')[1], 'Analysing data')
  t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, dirname + '.html'), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

test('clinic bubbleprof -- node - no issues', function (t) {
 // collect data
 cli({}, [
  'clinic', 'bubbleprof', '--no-open',
  '--', 'node', '-e', 'setTimeout(() => {}, 100)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-bubbleprof)/)[1]
  const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

  t.strictEqual(stdout.split('\n')[1], 'Analysing data')
  t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, dirname + '.html'), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
origin: clinicjs/node-clinic

test('clinic doctor -- node - no issues', function (t) {
 // collect data
 cli({}, [
  'clinic', 'doctor', '--no-open',
  '--', 'node', '-e', 'setTimeout(() => {}, 400)'
 ], function (err, stdout, stderr, tempdir) {
  t.ifError(err)
  const dirname = stdout.match(/(\.clinic[/\\]\d+.clinic-doctor)/)[1]
  const fullpath = url.pathToFileURL(fs.realpathSync(path.resolve(tempdir, dirname)))

  t.strictEqual(stdout.split('\n')[1], 'Analysing data')
  t.strictEqual(stdout.split('\n')[2], `Generated HTML file is ${fullpath}.html`)

  // check that files exists
  async.parallel({
   sourceData (done) {
    fs.access(path.resolve(tempdir, dirname), done)
   },
   htmlFile (done) {
    fs.access(path.resolve(tempdir, dirname + '.html'), done)
   }
  }, function (err) {
   t.ifError(err)
   t.end()
  })
 })
})
async(npm)

JSDoc

Higher-order functions and common patterns for asynchronous code

Most used async functions

  • waterfall
  • callback
  • series
  • parallel
  • each
  • next,
  • cb,
  • map,
  • done,
  • queue,
  • AsyncQueue.push,
  • mapLimit,
  • whilst,
  • eachLimit,
  • forEach,
  • auto,
  • forEachOf,
  • mapSeries,
  • forEachSeries

Popular in JavaScript

  • redis
    Redis client library
  • express
    Fast, unopinionated, minimalist web framework
  • debug
    small debugging utility
  • readable-stream
    Streams3, a user-land copy of the stream library from Node.js
  • request
    Simplified HTTP request client.
  • superagent
    elegant & feature rich browser / node HTTP with a fluent API
  • handlebars
    Handlebars provides the power necessary to let you build semantic templates effectively with no frustration
  • through2
    A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise
  • q
    A library for promises (CommonJS/Promises/A,B,D)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now