From 4bb10531bb50cc3fa7adf30232c04c346f346bd6 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sat, 10 Oct 2015 22:34:12 -0700 Subject: [PATCH] created a non-blocking router --- non_blocking_router.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 non_blocking_router.go diff --git a/non_blocking_router.go b/non_blocking_router.go new file mode 100644 index 0000000..a2381af --- /dev/null +++ b/non_blocking_router.go @@ -0,0 +1,30 @@ +package flog + + +// NewNonBlockingRouter returns an initialized NonBlockingRouter. +func NewNonBlockingRouter(subrouter Router) *NonBlockingRouter { + router := NonBlockingRouter{ + subrouter:subrouter, + } + + return &router +} + + +// NonBlockingRouter is a Router when its Route method is call its does not +// block and dealing with the routing in parallel. +// +// Note that this means that if the application could terminate before this +// completes. +type NonBlockingRouter struct { + subrouter Router +} + + +func (router *NonBlockingRouter) Route(message string, context map[string]interface{}) error { + go func() { + router.subrouter.Route(message, context) + }() + + return nil +}