Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-27 Thread b.ca...@pobox.com
I should add: using channels often means the mutex is not required. Imagine, for example, that you want a concurrency-safe counter (that multiple goroutines can read, increment and decrement). You can put the counter value into a buffered channel: counter := make(chan int, 1) counter <- 0

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-27 Thread Afriyie Abraham Kwabena
Hi, THanks!! BR Abraham On Friday, November 27, 2020 at 11:12:53 AM UTC+2 b.ca...@pobox.com wrote: > On Friday, 27 November 2020 at 06:14:48 UTC Afriyie Abraham Kwabena wrote: > >> What I would like to ask is, using mutex OK and if not the best way of >> solving it, how can i use >> channels

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-27 Thread b.ca...@pobox.com
On Friday, 27 November 2020 at 06:14:48 UTC Afriyie Abraham Kwabena wrote: > What I would like to ask is, using mutex OK and if not the best way of > solving it, how can i use > channels in this case. > There's nothing wrong with mutex, but you can use channels for a more native-Go experience.

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-26 Thread Afriyie Abraham Kwabena
Hi, I just produce the warning for clarity. sorry for the huge message == WARNING: DATA RACE Write at 0x00c0002d6480 by goroutine 48: runtime.mapdelete_faststr() /usr/local/go/src/runtime/map_faststr.go:297 +0x0 nfnrfapi/services/manag.UpdateNFInstance()

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-26 Thread Afriyie Abraham Kwabena
Hi, Yes from the warning it prints the handler function below and after google searching what i did was to mutex.Lock and Unlock the handler function and no warning again. However, my google search people mention of using channels instead of mutex. What I would like to ask is, using mutex OK

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-26 Thread Shulhan
> On 27 Nov 2020, at 07.06, Afriyie Abraham Kwabena > wrote: > > Hi, > > Am experiencing data race warning with my pollingworker function below even > though when i build with the -race flag i do not get any error. Any help? > Usually when you got data race warning it will print the

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-26 Thread Afriyie Abraham Kwabena
Hi, Am experiancing data race warning with my pollingworker function below even though when i build with the -race flag i do not get any error. Any help? func PollingWorker() { tiker := time.NewTicker(60 * time.Second) for _ = range tiker.C { mu.Lock() for keyid :=

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-18 Thread Afriyie Abraham Kwabena
Hi Sulhan, Anderson, Thanks for your guidance. It works now using time.Ticker func worker() { tiker := time.NewTicker(30 * time.Second) for _ = range tiker.C { mu.Lock() for keyid := range idtime { d := time.Now().Unix() - idtime[keyid] if d >=

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Shulhan
> On 18 Nov 2020, at 01.06, Afriyie Abraham Kwabena > wrote: > > Hi, > > The UpdateData function is the HTTP handler for the route which matches the > URL and is called after the mux.Router after receiving an incoming request > matches the incoming request > against the registered

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Afriyie Abraham Kwabena
Hi, The UpdateData function is the HTTP handler for the route which matches the URL and is called after the mux.Router after receiving an incoming request matches the incoming request against the registered route. BR Afriyie On Tuesday, November 17, 2020 at 7:33:50 PM UTC+2 Afriyie

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Afriyie Abraham Kwabena
Hi, I have made changes according to the comments and also simply the main function but am not sure if the worker go routine works. This what i did: type Route struct { Namestring Method string Pattern string HandlerFunc http.HandlerFunc } var idtime =

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Shulhan
Hi Afriyie, Looks like you almost there ;) > On 17 Nov 2020, at 20.11, Afriyie Abraham Kwabena > wrote: > > HI, > > This is what I have tried so far but am not able to get the time difference > in seconds. I mean the time differences between the time stored in the > map[string]time.Time

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Afriyie Abraham Kwabena
HI, This is what I have tried so far but am not able to get the time difference in seconds. I mean the time differences between the time stored in the map[string]time.Time and the current time in seconds. code: type Server struct { idtime map[string]time.Time } var my = Server{} func

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-17 Thread Anderson Queiroz
Just one thing to keep in mind. Likely you have more than one serve instance running to process the requests. Thus it might happen the client will poll a different server on every request. Just imagine you have servers A, B, C behind a load balance and the domain example.com. As the client is

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-16 Thread Shulhan
> On 16 Nov 2020, at 16.24, Afriyie Abraham Kwabena > wrote: > > Hi , > > You are right but am new to programming and currently this what i have done. > I have an http server handler that receives the PATCH request and stores the > id and the current time stamp of the request. > But my

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-16 Thread Afriyie Abraham Kwabena
Hi , You are right but am new to programming and currently this what i have done. I have an http server handler that receives the PATCH request and stores the id and the current time stamp of the request. But my problem is how to write the worker function to do the clean up every X seconds.

Re: [go-nuts] How to detect HTTP client stop polling at the server side

2020-11-14 Thread Shulhan
> On 14 Nov 2020, at 20.06, Afriyie Abraham Kwabena > wrote: > > Hi, > > My question is about multiple HTTP client polling an HTTP server randomly > with a PATCH request to update a resource at the server running in front of > MongoDB. The clients poll with their different ids and a

[go-nuts] How to detect HTTP client stop polling at the server side

2020-11-14 Thread Afriyie Abraham Kwabena
Hi, My question is about multiple HTTP client polling an HTTP server randomly with a PATCH request to update a resource at the server running in front of MongoDB. The clients poll with their different ids and a valid time in their request. At the server, I can keep their ids and their