How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • // passing a regular synchronous function
    async.waterfall([
        async.apply(fs.readFile, filename, "utf8"),
        async.asyncify(JSON.parse),
        function (data, next) {
            // data is the result of parsing the text.
            // If there was a parsing error, it would have been caught.
        }
    ], callback);
    
    // passing a function returning a promise
    async.waterfall([
        async.apply(fs.readFile, filename, "utf8"),
        async.asyncify(function (contents) {
            return db.model.create(contents);
        }),
        function (model, next) {
            // `model` is the instantiated model object.
            // If there was an error, this function would be skipped.
        }
    ], callback);
    
    // es2017 example, though `asyncify` is not needed if your JS environment
    // supports async functions out of the box
    var q = async.queue(async.asyncify(async function(file) {
        var intermediateStep = await processFile(file);
        return await somePromise(intermediateStep)
    }));
    
    q.push(files);
    Docs
  • // using apply
    async.parallel([
        async.apply(fs.writeFile, 'testfile1', 'test1'),
        async.apply(fs.writeFile, 'testfile2', 'test2')
    ]);
    
    
    // the same process without using apply
    async.parallel([
        function(callback) {
            fs.writeFile('testfile1', 'test1', callback);
        },
        function(callback) {
            fs.writeFile('testfile2', 'test2', callback);
        }
    ]);
    
    // It's possible to pass any number of additional arguments when calling the
    // continuation:
    
    node> var fn = async.apply(sys.puts, 'one');
    node> fn('two', 'three');
    one
    two
    three
    Docs
  • const {GoogleAuth} = require('google-auth-library');
    
    /**
    * Instead of specifying the type of client you'd like to use (JWT, OAuth2, etc)
    * this library will automatically choose the right client based on the environment.
    */
    async function main() {
      const auth = new GoogleAuth({
        scopes: 'https://www.googleapis.com/auth/cloud-platform'
      });
      const client = await auth.getClient();
      const projectId = await auth.getProjectId();
      const url = `https://dns.googleapis.com/dns/v1/projects/${projectId}`;
      const res = await client.request({ url });
      console.log(res.data);
    }
    
    main().catch(console.error);
    Docs
  • import {setupBrowser} from '@testing-library/webdriverio'
    
    it('can click button', async () => {
      const {getByText} = setupBrowser(browser)
    
      const button = await getByText('Button Text')
      await button.click()
    
      expect(await button.getText()).toEqual('Button Clicked')
    })
    Docs
  • const applyAsync = (acc,val) => acc.then(val);
    const composeAsync = (...funcs) => x => funcs.reduce(applyAsync, Promise.resolve(x));
    
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples