Ian Cottrell 8962968d5a internal/lsp: add the worker package
This is used by all the telemetry packages that come next

Change-Id: Ic84d91da2a792b53ee8839aae207ae5767ab17e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184940
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 19:45:51 +00:00

31 lines
898 B
Go

// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package worker provides a very simple mechanism to allow telemetry packages
// to work cooperatively and efficiently.
package worker
var (
workQueue = make(chan func(), 100)
)
func init() {
go func() {
for task := range workQueue {
task()
}
}()
}
// Do adds a task to the list of things to work on in the background.
// All tasks will be handled in submission order, and no two tasks will happen
// concurrently so they do not need to do any kind of locking.
// It is safe however to call Do concurrently.
// No promises are made about when the tasks will be performed.
// This function may block, but in general it will return very quickly and
// before the task has been run.
func Do(task func()) {
workQueue <- task
}