<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[modern-go - Medium]]></title>
        <description><![CDATA[Modern Go Programming - Medium]]></description>
        <link>https://medium.com/modern-go?source=rss----87467154d140---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>modern-go - Medium</title>
            <link>https://medium.com/modern-go?source=rss----87467154d140---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:41:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/modern-go" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Use goroutine like thread]]></title>
            <link>https://medium.com/modern-go/use-goroutine-like-thread-8d5052c3c906?source=rss----87467154d140---4</link>
            <guid isPermaLink="false">https://medium.com/p/8d5052c3c906</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Wen Tao]]></dc:creator>
            <pubDate>Fri, 02 Mar 2018 03:43:49 GMT</pubDate>
            <atom:updated>2018-03-02T08:02:43.876Z</atom:updated>
            <content:encoded><![CDATA[<p>Go has a awesome language feature called “goroutine”. However, I miss the old school “thread” api sometime. There are two features missing:</p><ul><li>cancel and wait the goroutine quit</li><li>unhandled panic handler</li></ul><p>So, here is what I come up, a tiny library <a href="https://github.com/modern-go/concurrent">https://github.com/modern-go/concurrent</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a890fd5f3f094f75190cfa343c91a418/href">https://medium.com/media/a890fd5f3f094f75190cfa343c91a418/href</a></iframe><p>It is a very simple library to attach the started goroutine to a executor object. One executor object can be used by manage just one or many goroutines.</p><p>You can choose to</p><ul><li>Stop: the goroutine will quit sometime later</li><li>StopAndWait: we will wait, until you cancel the wait</li><li>StopAndWaitForever: will until the goroutine has quit</li></ul><p>It is useful to use stop and wait to graceful shutdown my service. But it is annoying to wait without knowing which goroutine is blocking in the way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e2a6df9d440b6910678081cd59c8e84/href">https://medium.com/media/3e2a6df9d440b6910678081cd59c8e84/href</a></iframe><p>when we set InfoLogger, we can see who is blocking</p><pre>UnboundedExecutor is still waiting goroutines to quit startFrom /home/xiaoju/workspace/src/github.com/modern-go/concurrent/unbounded_executor_test.go:25 count 1<br>...<br>goroutine exited<br>executor stopped</pre><p>Internally, we are using the function line number to identify the goroutine. And every goroutine life-cycle is tracked, so we know exactly “who” and “how many” is still hanging there.</p><p>Another thing we would like to provide is how panic is handled. The default behavior of goroutine is to crash the process. Sometimes, this behavior is desirable. Sometimes, it is not. We would like to make the “default” behavior user defined.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33882bf52c0c6fce2fdaf52452e51f63/href">https://medium.com/media/33882bf52c0c6fce2fdaf52452e51f63/href</a></iframe><p>by defining concurrent.HandlePanic, we can control how unhandled goroutine panic will be handled globally. If we want to more fine grained control, we can set HandlePanic in the executor level as well.</p><p>Hope you will find it useful, and give me a star: <a href="https://github.com/modern-go/concurrent">https://github.com/modern-go/concurrent</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d5052c3c906" width="1" height="1" alt=""><hr><p><a href="https://medium.com/modern-go/use-goroutine-like-thread-8d5052c3c906">Use goroutine like thread</a> was originally published in <a href="https://medium.com/modern-go">modern-go</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>