Code Monkey home page Code Monkey logo

Comments (3)

reggi avatar reggi commented on August 17, 2024

I was just a little bit off 🌈 🐰 :shipit: 🍖

function execModify(command, manipulators, callback) {
  return asyncawait(function(command, manipulators) {
    var exec = Promise.promisify(childProcess.exec);
    var stdout = await(exec(command))[0];
    if (!manipulators) return stdout;
    for (var key in manipulators) {
      var manipulator = manipulators[key];
      stdout = manipulator(stdout);
    }
    return stdout;
  })(command, manipulators).nodeify(callback);
}

from asyncawait.

yortus avatar yortus commented on August 17, 2024

Hi @reggi, a couple of suggestions:

  1. For better performance, run the var exec = Promise.promisify... line only once, not on every call
  2. async.cps is a variant of async that will return a node-style callback function, no need for .nodeify.

With those two changes, your code would look something like:

var exec = Promise.promisify(childProcess.exec);

var execModify = async.cps (function (command, manipulators) {
    var stdout = await (exec(command))[0];
    if (!manipulators) return stdout;
    return _.map(manipulators, function(manipulator) {
      return manipulator(stdout);
    });
  });

// execModify now has a node-style API, so call it like:
execModify(myCommand, myManipulators, function (err, result) {...});

from asyncawait.

reggi avatar reggi commented on August 17, 2024

Thanks @yortus!!! Great library! This is really cool stuff.

from asyncawait.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.