Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

github.com/hiroygo/concurrency_in_go

Package Overview
Dependencies
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hiroygo/concurrency_in_go

Source
Go Modules
Version
v0.0.0-20201213092536-5977df6f30f1
Version published
Created
Source

concurrency_in_go

  • Go言語による並行処理 を読んで書いてみたプログラム

日本語版サポートページ

  • https://github.com/oreilly-japan/concurrency-in-go-support

原著サンプルコード

メモ

p47

  • struct{} は空構造体と呼ばれる。メモリを消費しない
  • 計測などに使うとよい

p49

  • ゴルーチンがスケジュールされるタイミングにはなんの保証もない
  • sync.WaitGroup の Add はできる限りゴルーチンの直前に書く
var wg sync.WaitGroup

// ゴルーチンの外側で Add する
// ゴルーチンの内側で Add すると Add 前に Wait が実行されて
// ゴルーチン終了の待機が行われない可能性がある
wg.Add(1)

go func() {
    defer wg.Done()
    fmt.Println("Hello")
}()

wg.Wait()

p77

  • チャネルの作成者の責任: チャネルの初期化、チャネルのクローズ
  • チャネル利用者では値の読み込みだけする

p90

  • スライスの範囲を分割することで mutex を使わずに済む

p143

  • ctx.Deadline() を使うことでタイムアウト発生前に処理を中断できる

p151

  • エラーの型を確認することで、そのエラーが想定内のエラーなのかバグなのかを区別する

FAQs

Package last updated on 13 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts