File: comment_4_8b1f65f141ffd9813e7f5a3380f7f520._comment

package info (click to toggle)
git-annex 5.20141125
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 37,828 kB
  • ctags: 583
  • sloc: haskell: 42,582; sh: 1,080; ansic: 498; makefile: 316; perl: 125
file content (27 lines) | stat: -rw-r--r-- 1,090 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[[!comment format=mdwn
 username="http://claimid.com/strager"
 ip="173.228.13.253"
 subject="comment 4"
 date="2012-08-11T16:08:47Z"
 content="""
> How to cancel download?  Depends on its implementation ....  So it's an abstraction layer violation problem.

Precisely why I suggested returning something as generic as `IO ()`:

    -- Current
    download :: URLString -> Headers -> [CommandParam] -> FilePath -> IO Bool

    -- Suggestion
    data Transfer a = Transfer { run :: IO a, cancel :: IO () }
    download :: URLString -> Headers -> [CommandParam] -> FilePath -> Transfer

    transfer <- download ...
    -- You can pass `cancel transfer` to another thread
    -- which you want to be able to cancel the transfer.
    run transfer  -- blocking

I realized while writing this that you may not get any result from e.g. a download while it is occurring (because the function is blocking).  Maybe that's where a misunderstanding occurred.  I separated the concepts of creating a transfer and starting/canceling it.

(My idea is starting to feel a bit object-oriented...  ;P)

"""]]