Giter Club home page Giter Club logo

DoAsync logo

NPM Version NPM Downloads GitHub issues Telegram Tweet

Welcome to the async world!

Hey! I’m a tiny little npm module - doasync. ~40 lines of code! Don’t ignore me, I’m very helpful! With me you can call any method of your object without a callback and receive a promise! Object is not modified! Cool, ha?

I can promisify functions as well (not only objects) with the help of util.promisify. But first of all, we must give credit to Proxy and ES6 guys... WeakMap has also proved useful.


Installation

npm i --save doasync

Usage

With objects:

const fs = require('fs');
const doAsync = require('doasync');

doAsync(fs).readFile('package.json', 'utf8')
  .then(result => {
    console.dir(JSON.parse(result), {colors: true});
  });

With functions:

doAsync(request)('http://www.google.com')
  .then(({body}) => {
    console.log(body);
    // ...
  });

You can even use native call and apply to bind some context:

doAsync(myFunc).apply(context, params)
  .then(result => { /*...*/ });

util.promisify() which is under the hood of this module can interact directly with the V8 API, so it doesn't create closures and will be faster than userland implementations.

Memoization is used in the module to prevent functions from being promisified each time (with the use of WeakMaps).

You can use it in async/await of course!

Tip


If you need a custom promisify function - use util.promisify.custom

Ruslan @doasync's Projects

doasync icon doasync

Promisify functions and objects immutably

fry icon fry

Tiny declarative HTTP client based on the browser Fetch API

fry-fx icon fry-fx

Create self-cancellable fetch effects

handsontable icon handsontable

Handsontable Community Edition - JavaScript/HTML5 Spreadsheet Component for Web Apps

history icon history

Manage session history with JavaScript

once-only icon once-only

Create a once-only function and it will be never repeated

package-build-stats icon package-build-stats

This is the cloud function that powers the core of building, minifying and gzipping of packages in bundlephobia

parcel-project icon parcel-project

Create a project with Parcel, Babel 7, React, Flow, ESLint, Prettier, Jest

patronum icon patronum

☄️ Effector utility library delivering modularity and convenience

pino-tee icon pino-tee

🌲 tee pino logs into a file, with multiple levels

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.