Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing channel to cancel a diff #7

Open
amlwwalker opened this issue Jun 11, 2019 · 1 comment
Open

Passing channel to cancel a diff #7

amlwwalker opened this issue Jun 11, 2019 · 1 comment

Comments

@amlwwalker
Copy link

Hello!
This is a cool bit of work.
I am looking to cancel a diff (on large files where the diff takes time), I want to pass a channel into the function that gets checked for a message (on a switch case) and if a value comes off the channel, it cancels the diff and stops in its tracks and cleans up.

My questions.

Where best to put the channel? I am thinking to fork your work.

There is the line of code:

binarydist/diff.go

Lines 234 to 240 in 190e7de

for scan < len(nbuf) {
var oldscore int
scan += length
for scsc := scan; scan < len(nbuf); scan++ {
pos, length = search(I, obuf, nbuf[scan:], 0, len(obuf))
for ; scsc < scan+length; scsc++ {

I.e the

for scan < len(nbuf) { 

line of code.

If I pass a channel into this function, and then inside the for loop, do a switch case can I stop the diff safely and destroy whatever diffing has already occured and pass back a success message?
Its just because on larger files diffing can take some time and I'd like to be able to stop it...

Thanks!

@kr
Copy link
Owner

kr commented Jun 12, 2019

Given the way binarydist is currently implemented, a fork sounds reasonable.

(I think it would be preferable for binarydist to write the diff directly to the given Writer (if it's also a Seeker) rather than to a buffer. If it did, you could have the Writer cancel the diff by returning an error. But of course that would require some changes to this library.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants