<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tick | www.valeriofinazzo.it</title>
	<atom:link href="http://www.valeriofinazzo.it/wordpress/tag/tick/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.valeriofinazzo.it/wordpress</link>
	<description>Il sito dell&#039;ingegnere Valerio Finazzo</description>
	<lastBuildDate>Fri, 30 Oct 2020 16:40:32 +0000</lastBuildDate>
	<language>it-IT</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.3</generator>
	<item>
		<title>TUTORIAL GO &#8211; GESTIONE DEI TIMER E DEI TICK</title>
		<link>http://www.valeriofinazzo.it/wordpress/2020/08/tutorial-go-gestione-dei-timer-e-dei-tick/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 20 Aug 2020 21:08:13 +0000</pubDate>
				<category><![CDATA[GOLANG]]></category>
		<category><![CDATA[GO]]></category>
		<category><![CDATA[tick]]></category>
		<category><![CDATA[timer]]></category>
		<guid isPermaLink="false">http://www.valeriofinazzo.it/wordpress/?p=626</guid>

					<description><![CDATA[<p>Go gestisce il tempo tramite gli oggetti timer e tick. Il timer rappresenta un evento che si verifica una sola volta e si manifesta tramite l&#8217;invio di un dato su un channel ad esso associato. Nell&#8217;esempio ho definito un timer che scatta dopo 2 secondi e una goroutine che allo scadere del timer darà evidenza &#8230; <a href="http://www.valeriofinazzo.it/wordpress/2020/08/tutorial-go-gestione-dei-timer-e-dei-tick/" class="more-link">Continua la lettura di <span class="screen-reader-text">TUTORIAL GO &#8211; GESTIONE DEI TIMER E DEI TICK</span> <span class="meta-nav">&#8594;</span></a></p>
The post <a href="http://www.valeriofinazzo.it/wordpress/2020/08/tutorial-go-gestione-dei-timer-e-dei-tick/">TUTORIAL GO – GESTIONE DEI TIMER E DEI TICK</a> first appeared on <a href="http://www.valeriofinazzo.it/wordpress">www.valeriofinazzo.it</a>.]]></description>
										<content:encoded><![CDATA[<p>Go gestisce il tempo tramite gli oggetti timer e tick. Il timer rappresenta un evento che si verifica una sola volta e si manifesta tramite l&#8217;invio di un dato su un channel ad esso associato.</p>



<pre class="crayon-plain-tag">package main

import (
	&quot;fmt&quot;
	&quot;time&quot;
)

func main() {

	timer := time.NewTimer(time.Second * 2)

	go func() {
		&amp;lt;-timer.C
		fmt.Println(&quot;Passati 2 secondi&quot;)
	}()

	time.Sleep(time.Second * 5)
}</pre>



<p>Nell&#8217;esempio ho definito un timer che scatta dopo 2 secondi e una goroutine che allo scadere del timer darà evidenza a video del tempo trascorso. La goroutine aspetta il valore inviato sul channel, attributo dell&#8217;oggetto timer. Questo meccanismo ci permette di impostare agevolmente dei timeout nel nostro codice.  Tramite la funzione Stop del timer possiamo evitare la sua attivazione.</p>



<pre class="crayon-plain-tag">go func() {
		timer.Stop()
	}()</pre>



<p>Qualora si voglia effettuare delle operazioni ad intervalli regolari Go mette a disposizione l&#8217;oggetto Ticker</p>



<pre class="crayon-plain-tag">ticker := time.NewTicker(time.Second * 1)
	go func() {
		for t := range ticker.C {
			fmt.Println(&quot;Ticker&quot;, t.Second())
			if t.Second() == 10 {
				ticker.Stop()
			}
		}
	}()</pre>



<p>Nell&#8217;esempio  ho creato un oggetto che inserisce un messaggio nel channel a intervalli regolari di un secondo. Anche il ticker presente una funzione Stop che consente di interrompere l&#8217;esecuzione del ticker.</p>
<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.valeriofinazzo.it%2Fwordpress%2F2020%2F08%2Ftutorial-go-gestione-dei-timer-e-dei-tick%2F&amp;linkname=TUTORIAL%20GO%20%E2%80%93%20GESTIONE%20DEI%20TIMER%20E%20DEI%20TICK" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.valeriofinazzo.it%2Fwordpress%2F2020%2F08%2Ftutorial-go-gestione-dei-timer-e-dei-tick%2F&amp;linkname=TUTORIAL%20GO%20%E2%80%93%20GESTIONE%20DEI%20TIMER%20E%20DEI%20TICK" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fwww.valeriofinazzo.it%2Fwordpress%2F2020%2F08%2Ftutorial-go-gestione-dei-timer-e-dei-tick%2F&amp;linkname=TUTORIAL%20GO%20%E2%80%93%20GESTIONE%20DEI%20TIMER%20E%20DEI%20TICK" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=http%3A%2F%2Fwww.valeriofinazzo.it%2Fwordpress%2F2020%2F08%2Ftutorial-go-gestione-dei-timer-e-dei-tick%2F&amp;linkname=TUTORIAL%20GO%20%E2%80%93%20GESTIONE%20DEI%20TIMER%20E%20DEI%20TICK" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_google_gmail" href="https://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fwww.valeriofinazzo.it%2Fwordpress%2F2020%2F08%2Ftutorial-go-gestione-dei-timer-e-dei-tick%2F&amp;linkname=TUTORIAL%20GO%20%E2%80%93%20GESTIONE%20DEI%20TIMER%20E%20DEI%20TICK" title="Gmail" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=http%3A%2F%2Fwww.valeriofinazzo.it%2Fwordpress%2F2020%2F08%2Ftutorial-go-gestione-dei-timer-e-dei-tick%2F&#038;title=TUTORIAL%20GO%20%E2%80%93%20GESTIONE%20DEI%20TIMER%20E%20DEI%20TICK" data-a2a-url="http://www.valeriofinazzo.it/wordpress/2020/08/tutorial-go-gestione-dei-timer-e-dei-tick/" data-a2a-title="TUTORIAL GO – GESTIONE DEI TIMER E DEI TICK"></a></p>The post <a href="http://www.valeriofinazzo.it/wordpress/2020/08/tutorial-go-gestione-dei-timer-e-dei-tick/">TUTORIAL GO – GESTIONE DEI TIMER E DEI TICK</a> first appeared on <a href="http://www.valeriofinazzo.it/wordpress">www.valeriofinazzo.it</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
