Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

lazy-await

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy-await

asdf

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

lazy promise

asdf

Install

npm install lazy-await

Usage

given

    class A {
        constructor() {
            this.self = this;
        }

        async b(val) {
            console.log(val);

            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(new B);
                }, 100);
            });
        }
    }

    class B {
        constructor() {
            this.primitive = 'primitive';

            this.promiseThis = Promise.resolve(this);
        }

        async a(val) {
            console.log(val);

            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve(new A);
                }, 100);
            });
        }
    }
    const a = new A;

    const ra = (await (await (await (await a.self.b(1)).a(2)).self.b(3)).promiseThis).primitive;

    console.log(ra);
    // expected output: 'primitive'

now becomes

    import proxy from 'lazy-await';

    const pa = proxy(new A);

    const rpa = await pa.self.b(1).a(2).self.b(3).promiseThis.primitive;

    console.log(rpa);
    // expected output: 'primitive'

Keywords

lazy

FAQs

Package last updated on 27 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts