Giter VIP home page Giter VIP logo

Comments (7)

sergiou87 avatar sergiou87 commented on July 26, 2024 4

I'm not particularly convinced about that specific approach, to be honest, it feels a bit hacky to me 😳

I think this would require a bigger API change:

  • Create a new abstraction called, let's say, GitTask, which represents a git process.
  • This abstraction would have:
    • An internal private property storing the PID of the git process (or something equivalent).
    • A result: Promise<IGitResult> property to obtain the result of the process.
    • A method like cancel() to kill the process while it's running. I imagine the implementation of this method would kill the process using its PID and somehow signal that the process was cancelled.
  • exec would return a GitTask instance instead of Promise<IGitResult>.

With that change, code that now looks like this:

const result = await exec()

Would look like this:

const task = exec()
const result = await task.result

And you can invoke task.cancel() to kill it at any time. That means IGitResult might need an additional field to indicate when the process was cancelled.

Does that make sense? 😳  I'm open to feedback and other suggestions about this 😄  My main concern is that this breaks the current API… but maybe we can create a new execTask function that returns this GitTask, and then implement the existing exec like this:

public static exec(args: string[], path: string, options?: IGitExecutionOptions,pidCallback?: (pid: number) => void): Promise<IGitResult> {
  const task = execTask()
  return task.result
}

@tidy-dev What do you think?

from dugite.

tidy-dev avatar tidy-dev commented on July 26, 2024 2

@sergiou87 All makes sense to me and like the bit about making an execTask to reduce implementation impact.

from dugite.

maifeeulasad avatar maifeeulasad commented on July 26, 2024

And if this is getting implemented, can I get assigned to this?

from dugite.

sergiou87 avatar sergiou87 commented on July 26, 2024

Hey @maifeeulasad! 👋

Thank you for your suggestion. However, I think that wouldn't be very useful because IGitResult represents the result of the git process once it's finished. At that point, the PID is not valid because the process doesn't exist anymore 😓

You would need to return the PID along with the Promise<IGitResult>, but that wouldn't end in a very clean API, in my opinion 😞

from dugite.

maifeeulasad avatar maifeeulasad commented on July 26, 2024

@sergiou87 can we pass an additional optional callback function, like this and that will return us the PID ?

public static exec(args: string[], path: string, options?: IGitExecutionOptions,pidCallback?: (pid: number) => void): Promise<IGitResult>;

Then we have the pid, check if it is undefined or not, if not, then we can use it to kill or other purposes.
This is what I thought of till now.

from dugite.

maifeeulasad avatar maifeeulasad commented on July 26, 2024

@sergiou87 damn, this is so cool
can I take part in the implementation?

from dugite.

sergiou87 avatar sergiou87 commented on July 26, 2024

Absolutely @maifeeulasad! ❤️

Please, consider adding some tests around that new cancel method to make sure it works as expected before we attempt to use it in GitHub Desktop 😄

Thank you for your work!

from dugite.

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.