Git Product home page Git Product logo

Comments (7)

sindresorhus avatar sindresorhus commented on July 18, 2024

Sure. Pull request welcome.

Just some quick feedback. It's not immediately clear to me why I would want to use p-signal over using AbortController directly. I think the readme could make that clearer.

from p-cancelable.

astoilkov avatar astoilkov commented on July 18, 2024

Sure. Pull request welcome.

Cool. Thanks!

Just some quick feedback. It's not immediately clear to me why I would want to use p-signal over using AbortController directly. I think the readme could make that clearer.

Aha. I guess that's because of the bad example I gave with pSignal(signal, fetch(url)) because it's better to do fetch(url, { signal })? I've changed the example. Do you think that makes it clearer?

from p-cancelable.

sindresorhus avatar sindresorhus commented on July 18, 2024

It's still not clear to me why I would use it over plain AbortController. I would recommend writing it clearly in prose how it's better.

from p-cancelable.

astoilkov avatar astoilkov commented on July 18, 2024

Hmm. I think I'm missing something. I can't think of an easy way to do it with AbortController. If there was an easy alternative, I would also struggle to see why I would use p-signal over AbortController.

This means that either, there is an easy way I don't know, or I am missing something else.

Let's take a pseudo code for example:

for (const item of items) {
  await pSignal(signal, parseText(item.text))
}

How this can be written using AbortController?

Thoughts:

  • Maybe I should just say that using AbortController will be a lot more code.
  • I know that you have a lot of experience with open-source and I'm sure you are seeing something that I don't. I would be very happy if I can understand your thinking. That may help me in the future as well.

from p-cancelable.

sindresorhus avatar sindresorhus commented on July 18, 2024

If we take the example in your readme. I fail to see how it's actually getting aborted. It just seems that the await pSignal(AbortSignal.timeout(200), longRunningTask()) call does indeed get aborted, but await parseText(currentFile.text) will continue running in the background.

The important thing with AbortSignal is that it has to be passed down to every single method, otherwise, it will not actually do what you expect.

from p-cancelable.

sindresorhus avatar sindresorhus commented on July 18, 2024

How this can be written using AbortController?

You cannot easily write exactly the same code, but that's my point. You need to clearly show what problem it solves. Say someone is used to using AbortController, they wouldn't immediately see what problem this solves for them.

from p-cancelable.

astoilkov avatar astoilkov commented on July 18, 2024

Got it! I will update the readme.

Thank you ❤️

from p-cancelable.

Related Issues (19)

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.