Permalink
Browse files

Catch os.Interrupt signal with iris.PostInterrupt example added in co…

  • Loading branch information...
1 parent f1e0754 commit cfa092fe3b782060f8dad728593dc99a72dc8e91 @kataras committed Jan 11, 2017
Showing with 16 additions and 0 deletions.
  1. +2 −0 HISTORY.md
  2. +2 −0 iris.go
  3. +12 −0 plugin.go
View
@@ -25,6 +25,8 @@ iris.Plugins.PostInterrupt(func(s *Framework){
```
+- Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
+
## 6.0.7 -> 6.0.8
- Add `iris.UseTemplateFunc(functionName string, function interface{})`. You could always set custom template funcs by using each of [template engine's](https://github.com/kataras/go-template) configuration but this function will help newcomers to start creating their custom template funcs.
View
@@ -541,7 +541,9 @@ func (s *Framework) postServe() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
<-ch
+
// catch custom plugin event for interrupt
+ // Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
s.Plugins.DoPostInterrupt(s)
if !s.Plugins.PostInterruptFired() {
// if no PostInterrupt events fired, then I assume that the user doesn't cares
View
@@ -96,11 +96,13 @@ type (
// graceful shutdown can be done here
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
+ // Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
PostInterrupt(*Framework)
}
// PostInterruptFunc implements the simple function listener for the PostInterrupt(*Framework)
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
+ // Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
PostInterruptFunc func(*Framework)
// pluginPreClose implements the PreClose(*Framework) method
@@ -220,6 +222,15 @@ func (fn PostListenFunc) PostListen(station *Framework) {
fn(station)
}
+// PostInterrupt it's being called only one time, when os.Interrupt system event catched
+// graceful shutdown can be done here
+//
+// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
+// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
+func (fn PostInterruptFunc) PostInterrupt(station *Framework) {
+ fn(station)
+}
+
// PreClose it's being called only one time, BEFORE the Iris .Close method
// any plugin cleanup/clear memory happens here
//
@@ -540,6 +551,7 @@ func (p *pluginContainer) PostListenFired() bool {
// PostInterrupt adds a PostInterrupt plugin-function to the plugin flow container
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
+// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
func (p *pluginContainer) PostInterrupt(fn PostInterruptFunc) {
p.Add(fn)
}

0 comments on commit cfa092f

Please sign in to comment.