github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekaserv/observe_wrapper.go (about) 1 // Copyright © 2022. All rights reserved. 2 // Author: Ilya Stroy. 3 // Contacts: iyuryevich@pm.me, https://github.com/qioalice 4 // License: https://opensource.org/licenses/MIT 5 6 package ekaserv 7 8 import ( 9 "github.com/qioalice/ekago/v3/ekatime" 10 ) 11 12 type ( 13 // OnceInWithContextCallback is just a function alias for callback 14 // that you may use in WrapOnceInWithContext() function. 15 16 // TODO: Comment 17 OnceInForObserveCallback func(oc *ObserveController, ts ekatime.Timestamp) 18 ) 19 20 // WrapOnceInWithContextWaitGroup allows you to get ekatime.OnceInCallback 21 // from your OnceInWithContextWaitGroupCallback, 22 // provided both context.Context `ctx` and sync.WaitGroup `wg`. 23 // 24 // Your callback will receive your provided both of context.Context and sync.WaitGroup, 25 // along with ekatime.Timestamp that you may use. 26 // 27 // The main difference from WrapOnceInWithContext() is sync.WaitGroup's handling: 28 // This function will pass `wg` to your `cb` callback as is w/o any preparations. 29 // As an opposite, the WrapOnceInWithContext() won't pass `wg` to your callback 30 // but "protects" the call of your callback using sync.WaitGroup. 31 // 32 // It's useful to use this wrapper inside Observe()'s callback. 33 34 // TODO: Comment 35 func WrapOnceInWithContextWaitGroup(oc *ObserveController, cb OnceInForObserveCallback) ekatime.OnceInCallback { 36 return func(ts ekatime.Timestamp) { 37 cb(oc, ts) 38 } 39 }