[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-go-goroutines-concurrency-all--*":3,"academy-blog-translations-i8u3due8r65tubw":84},{"data":4,"page":72,"perPage":72,"totalItems":72,"totalPages":72},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":78,"keywords":79,"locale":54,"published_at":80,"scheduled_at":13,"school_blog":76,"short_description":81,"slug":82,"status":74,"title":6,"updated":83,"updated_by":13,"views":77},"EP.8 Go and Goroutines - Mastering Concurrent Work Like a Pro!","sclblg987654321","school_blog_translations","\u003Cp>\u003Cspan style=\"font-size:20px;\">\u003Cstrong>Go and Goroutines - Mastering Concurrent Work Like a Pro!\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Do you want your program to perform multiple tasks quickly? Today, we will teach you how to use Goroutines and Channels in Go that will make your program run smoothly and efficiently.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>What are Goroutines?\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>A Goroutine is a lightweight processing unit that Go uses for concurrent operations. When we create a Goroutine, Go runs it in the background without blocking the main program, allowing us to run multiple tasks simultaneously.\u003C\u002Fp>\u003Cp>Example of a Goroutine:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">package main\r\n\r\nimport (\r\n    \"fmt\"\r\n    \"time\"\r\n)\r\n\r\nfunc printNumbers() {\r\n    for i := 1; i &lt;= 5; i++ {\r\n        fmt.Println(i)\r\n        time.Sleep(500 * time.Millisecond)\r\n    }\r\n}\r\n\r\nfunc main() {\r\n    go printNumbers() \u002F\u002F สร้าง Goroutine\r\n    fmt.Println(\"Goroutine started\")\r\n    time.Sleep(3 * time.Second) \u002F\u002F รอให้ Goroutine ทำงานเสร็จ\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Channels: Communication Between Goroutines\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>Channels are used to send data between Goroutines, making concurrent operations safer and more organized.\u003C\u002Fp>\u003Cp>Example of a Channel:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func main() {\r\n    messages := make(chan string)\r\n\r\n    go func() {\r\n        messages &lt;- \"Hello from Goroutine\" \u002F\u002F ส่งข้อมูลผ่าน Channel\r\n    }()\r\n\r\n    msg := &lt;-messages \u002F\u002F รับข้อมูลจาก Channel\r\n    fmt.Println(msg)\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Buffered Channels:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>Channels can be buffered to hold multiple values:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func main() {\r\n    messages := make(chan string, 2) \u002F\u002F บัฟเฟอร์ได้ 2 ค่า\r\n\r\n    messages &lt;- \"First\"\r\n    messages &lt;- \"Second\"\r\n\r\n    fmt.Println(&lt;-messages)\r\n    fmt.Println(&lt;-messages)\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Controlling Concurrency with sync\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cbr>Go has a sync package for controlling concurrency, such as waiting for Goroutines to finish:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">import (\r\n    \"fmt\"\r\n    \"sync\"\r\n)\r\n\r\nfunc worker(wg *sync.WaitGroup, id int) {\r\n    fmt.Printf(\"Worker %d starting\\n\", id)\r\n    wg.Done() \u002F\u002F ลดตัวนับลง 1\r\n}\r\n\r\nfunc main() {\r\n    var wg sync.WaitGroup\r\n\r\n    for i := 1; i &lt;= 3; i++ {\r\n        wg.Add(1)\r\n        go worker(&amp;wg, i)\r\n    }\r\n\r\n    wg.Wait() \u002F\u002F รอให้ทุก Goroutine ทำงานเสร็จ\r\n    fmt.Println(\"All workers done\")\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>","16_11zon_t42x2fcsgq.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fvih3cz2bfizlkzn\u002F16_11zon_t42x2fcsgq.webp","2026-03-04 08:33:59.868Z","",{"keywords":15,"locale":48,"school_blog":58},[16,23,28,33,38,43],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:33:53.933Z","yyq22valznn0j0u","application development","2026-04-10 16:08:02.871Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:33:54.929Z","otkayeo8kz7u62p","sync","2026-04-10 16:08:03.333Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:33:55.714Z","yxs12a8pjduka2m","Channels","2026-04-10 16:08:03.494Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:24:48.143Z","dourw0uuydrrh1h","Concurrency","2026-04-10 16:07:30.157Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:33:58.044Z","nb6p1r8sfqlsxf8","Goroutines","2026-04-10 16:08:04.493Z",{"collectionId":17,"collectionName":18,"created":44,"created_by":13,"id":45,"name":46,"updated":47,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"code":49,"collectionId":50,"collectionName":51,"created":52,"flag":53,"id":54,"is_default":55,"label":56,"updated":57},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":59,"collectionId":60,"collectionName":61,"expand":62,"id":76,"views":77},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":63},{"blogIds":64,"collectionId":65,"collectionName":66,"created":67,"created_by":13,"id":59,"image":68,"image_alt":13,"image_path":69,"label":70,"name":71,"priority":72,"publish_at":73,"scheduled_at":13,"status":74,"updated":75,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":71,"th":71},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","i8u3due8r65tubw",207,"vih3cz2bfizlkzn",[20,25,30,35,40,45],"2025-01-22 05:02:22.709Z","Discover how to create Goroutines and utilize Channels to manage concurrent tasks in Go.","go-goroutines-concurrency","2026-04-25 02:47:29.486Z",{"en":82}]