The global var should have been protected by a mutex, or loaded and saved
using sync/atomic functions, as it is accessed from multiple goroutines.

Another minor point:

Why do:

result := fmt.Sprintf("Hello there %s", i)
io.WriteString(w, result)

instead of just:
fmt.Fprintf(w, "Hello there %s", i)



On Friday, 5 January 2018 23:58:01 UTC, matthe...@gmail.com wrote:
>
> Using a channel read in the http handler will block the ticker for loop 
> until the read occurs, but if you want that then pass mc into the generic 
> function: https://play.golang.org/p/GrHQxPhy1qu
>
> Using a buffered channel will keep the history of ticks and not block but 
> may run out of buffer space if the handler isn't called enough.
>
> Amnon's global var should work if you are just looking for the current 
> tick value.
>
> Matt
>
> On Friday, January 5, 2018 at 12:33:32 PM UTC-6, Amnon Baron Cohen wrote:
>>
>> try using a global var.
>> something like https://play.golang.org/p/05-xBDh5rgn
>>
>> On Thursday, 4 January 2018 15:09:41 UTC, Keith Brown wrote:
>>>
>>> I am trying to Serve a webpage while running a ticker in the background. 
>>> I am trying to generate a random number, genRandom() , periodically and 
>>> publish it on a channel so generic() can see the results. I have something 
>>> like this https://play.golang.org/p/6d1xmqpUYY7 but I don't know how to 
>>> get channel results to generic()? Do I need to make my mc channel a global? 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to