Skip to content

Commit

Permalink
Revert dig functions (#1)
Browse files Browse the repository at this point in the history
* Revert "Travis shield"

This reverts commit ad26a61.

* Revert "Added some helpers for using with dig"

This reverts commit 2822665.
  • Loading branch information
chapsuk authored Jul 5, 2018
1 parent ad26a61 commit 91b5357
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 90 deletions.
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

30 changes: 1 addition & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Grace pkg

[![Build Status](https://travis-ci.org/chapsuk/grace.svg?branch=master)](https://travis-ci.org/chapsuk/grace)

Package with single function for create base context which will be canceled on signals:
`SIGINT`, `SIGTERM`, `SIGHUP`.

Expand All @@ -12,39 +10,13 @@ package main

import (
"context"

"github.com/chapsuk/grace"
)

func main() {
ctx := grace.ShutdownContext(context.Background())
// context can be used for long time tasks or for what else
<-ctx.Done()
// do graceful shutdown after context was canceled
}
```

## Example with dig

```go
package main

import (
"github.com/chapsuk/grace"
"go.uber.org/dig"
)

func main() {
c := dig.New()

c.Provide(grace.NewShutdownContext)
c.Invoke(func(p grace.ContextParams) {
// nodes: {
// context.Context[name="grace_context"] -> deps: [], ctor: func() grace.ContextResult
// }
// values: {
// context.Context[name="grace_context"] => context.Background.WithCancel
// }
<-p.Context.Done()
})
}
```
30 changes: 0 additions & 30 deletions sahutdown_test.go

This file was deleted.

21 changes: 0 additions & 21 deletions shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"os"
"os/signal"
"syscall"

"go.uber.org/dig"
)

// ShutdownContext returns child context from passed context which will be canceled
Expand All @@ -21,22 +19,3 @@ func ShutdownContext(c context.Context) context.Context {
}()
return ctx
}

// ContextResult wrap grace context for dig usage
type ContextResult struct {
dig.Out
Context context.Context `name:"grace_context"`
}

// NewShutdownContext returns wrapped ShutdownContext func result for dig usage
func NewShutdownContext() ContextResult {
return ContextResult{
Context: ShutdownContext(context.Background()),
}
}

// ContextParams contains shutdown context for dig usage
type ContextParams struct {
dig.In
Context context.Context `name:"grace_context"`
}

0 comments on commit 91b5357

Please sign in to comment.