Skip to content

Commit

Permalink
Improve README.md and code coverage a bit.
Browse files Browse the repository at this point in the history
That said, Ctrl-C handling isn't unit tested but known to work.
  • Loading branch information
maruel committed Nov 9, 2014
1 parent fc4cb07 commit 58e7ad0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -12,19 +12,19 @@ When set, it is expected the process to abort any on-going execution early.

The signal can be read via two ways:

select {
case <- interrupt.Channel:
// Handle abort.
case ...
...
default:
}
select {
case <- interrupt.Channel:
// Handle abort.
case ...
...
default:
}

or

if interrupt.IsSet() {
// Handle abort.
}
if interrupt.IsSet() {
// Handle abort.
}

[![GoDoc](https://godoc.org/github.com/maruel/interrupt?status.svg)](https://godoc.org/github.com/maruel/interrupt)
[![Build Status](https://travis-ci.org/maruel/interrupt.svg?branch=master)](https://travis-ci.org/maruel/interrupt)
Expand Down
23 changes: 16 additions & 7 deletions interrupt_test.go
Expand Up @@ -18,12 +18,21 @@ func TestSet(t *testing.T) {
default:
}

HandleCtrlC()

ut.AssertEqual(t, false, IsSet())
select {
case <-Channel:
t.Fatal()
default:
}

Set()
ut.AssertEqual(t, true, IsSet())
i, ok := <-Channel
ut.AssertEqual(t, true, i)
ut.AssertEqual(t, true, ok)
i, ok = <-Channel
ut.AssertEqual(t, true, i)
ut.AssertEqual(t, true, ok)

for i := 0; i < 2; i++ {
ut.AssertEqual(t, true, IsSet())
x, ok := <-Channel
ut.AssertEqual(t, true, x)
ut.AssertEqual(t, true, ok)
}
}

0 comments on commit 58e7ad0

Please sign in to comment.