google / google/gonids

design question: lexer in goroutine?

Open
#19 4 comments 0 reactions 1 assignee Claimed by @julienschmidt View on GitHub
Dominant language
Go
Stars
198
Forks
50
PR merge metrics
No merged PRs in 30d

Description

While looking through the code, I noticed that the lexer runs its main loop its own goroutine:
```go
func lex(input string) (*lexer, error) {
...
l := &lexer{
input: input,
items: make(chan item),
}
go l.run()
return l, nil
}
```

Items are then received from the unbuffered channel `l.items` , thus making the code run fully sequential again.

Is there any other good reason to run it in it's own goroutine? If not, the overhead for synchronization and context switches could be avoided.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.