diff --git a/go-manual/modules/ROOT/pages/concurrency.adoc b/go-manual/modules/ROOT/pages/concurrency.adoc index cd8d4a9d..637f2dee 100644 --- a/go-manual/modules/ROOT/pages/concurrency.adoc +++ b/go-manual/modules/ROOT/pages/concurrency.adoc @@ -43,7 +43,7 @@ func main() { } // Run a query and get results in a channel - records_c := queryToChannel(ctx, driver) // <1> + recordsC := queryToChannel(ctx, driver) // <1> // Spawn some consumers that will process records // They communicate back on the log channel @@ -52,7 +52,7 @@ func main() { wg := &sync.WaitGroup{} // <5> for i := 1; i < 10; i++ { // i starts from 1 because 0th receiver would process too fast wg.Add(1) - go consumer(wg, records_c, log, i) // <6> + go consumer(wg, recordsC, log, i) // <6> } // When all consumers are done, close log channel go func() { @@ -66,7 +66,7 @@ func main() { } func queryToChannel(ctx context.Context, driver neo4j.DriverWithContext) chan *neo4j.Record { - records_c := make(chan *neo4j.Record, 10) // <2> + recordsC := make(chan *neo4j.Record, 10) // <2> session := driver.NewSession(ctx, neo4j.SessionConfig{DatabaseName: "neo4j"}) defer session.Close(ctx) go session.ExecuteWrite(ctx, @@ -83,12 +83,12 @@ func queryToChannel(ctx context.Context, driver neo4j.DriverWithContext) chan *n // Stream results to channel as they come from the server for result.Next(ctx) { // <3> record := result.Record() - records_c <- record + recordsC <- record } - close(records_c) + close(recordsC) return nil, err }) - return records_c + return recordsC } func consumer(wg *sync.WaitGroup, records <-chan *neo4j.Record, log chan string, n int) { @@ -102,15 +102,15 @@ func consumer(wg *sync.WaitGroup, records <-chan *neo4j.Record, log chan string, <1> A Goroutine runs the query to the Neo4j server with a xref:transactions.adoc[managed transaction]. Notice that the driver session is created _inside_ the routine, as sessions are not thread-safe. -<2> The channel `records_c` is where the query result records get streamed to. +<2> The channel `recordsC` is where the query result records get streamed to. The transaction function from `ExecuteWrite()` writes to it, and the various ``consumer``s read from it. It is buffered so that the driver does not retrieve records faster than what the consumers can handle. -<3> Each result record coming from the server is sent over the `records_c` channel. +<3> Each result record coming from the server is sent over the `recordsC` channel. The streaming continues so long as there are records to be processed, after which the channel gets closed and the routine exits. <4> The channel `log` is where the consumers comunicate on. <5> A `sync.WaitGroup` is needed to know when all consumers are done, and thus the `log` channel can be closed. <6> A number of ``consumer``s get started in separate Goroutines. -Each consumer reads and processes records from the `records_c` channel. +Each consumer reads and processes records from the `recordsC` channel. Each consumer simulates a lengthy operation with a sleeping timer.