mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
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>
This commit is contained in:
parent
4f9eeaf1bf
commit
8962968d5a
@ -4,4 +4,4 @@ go 1.11
|
||||
|
||||
require golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0
|
||||
|
||||
replace golang.org/x/tools => ../
|
||||
replace golang.org/x/tools => ../
|
||||
|
@ -1,5 +1,6 @@
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
30
internal/lsp/telemetry/worker/worker.go
Normal file
30
internal/lsp/telemetry/worker/worker.go
Normal file
@ -0,0 +1,30 @@
|
||||
// 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user