Giter Site home page Giter Site logo

Comments (8)

terkelg avatar terkelg commented on July 22, 2024

Hi @pvdlg.
I think this can be solved by making this function async and await the onSubmit. Can you try that? I'm open for a PR

from prompts.

pvdlg avatar pvdlg commented on July 22, 2024

Do you mean the onAbort function? It's a user defined function, what do you mean by making it async?

from prompts.

terkelg avatar terkelg commented on July 22, 2024

Sorry it was a bit rushed. But yes, something like this

function toPrompt(type, args, opts={}) {
  return new Promise((res, rej) => {
    const p = new el[type](args);
    const onAbort = opts.onAbort || noop;
    const onSubmit = opts.onSubmit || noop;
    p.on('state', args.onState || noop);
    p.on('submit', async x => res(await onSubmit(x)));
    p.on('abort', async x => rej(await onAbort(x)));
  });
}

from prompts.

pvdlg avatar pvdlg commented on July 22, 2024

Oh yes that's the idea but it currently doesn't work because the on function of p (an EventEmitter) doesn't seems to support async functions.

from prompts.

pvdlg avatar pvdlg commented on July 22, 2024

After a bit more investigation awaiting the onSubmit function here works.

Awaiting onSubmit or onAbort in toPrompt has no effect. Is that expect? Does it make sense to you?

from prompts.

terkelg avatar terkelg commented on July 22, 2024

Oh that's where we want to await. I see. Can you do a PR we can test?

from prompts.

pvdlg avatar pvdlg commented on July 22, 2024

Yes, I already opened it: #84

from prompts.

terkelg avatar terkelg commented on July 22, 2024

Thanks! Will be a part of v1.1.0

from prompts.

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.