Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Stat service wrapper (not optimized)
Browse files Browse the repository at this point in the history
  • Loading branch information
funny-falcon committed Oct 21, 2013
1 parent 60ed3ac commit 2a7bb69
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions stat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package iproto

import "time"

type StatService struct {
Service
F func(*Request, time.Duration)
}

func (ss *StatService) Send(r *Request) {
if r.ChainBookmark(&statBookmark{f: ss.F, e: NowEpoch()}) {
ss.Service.Send(r)
}
}

type statBookmark struct {
Bookmark
f func(*Request, time.Duration)
e Epoch
}

func (sm *statBookmark) Respond(res *Response) {
sm.f(sm.Request, sm.e.Elapsed())
}

func StatWrap(s Service, f func(*Request, time.Duration)) Service {
return &StatService{Service: s, F: f}
}

0 comments on commit 2a7bb69

Please sign in to comment.