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>
diff --git a/gopls/go.mod b/gopls/go.mod
index 641bdff..5fbc461 100644
--- a/gopls/go.mod
+++ b/gopls/go.mod
@@ -4,4 +4,4 @@
 
 require golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0
 
-replace golang.org/x/tools => ../
\ No newline at end of file
+replace golang.org/x/tools => ../
diff --git a/gopls/go.sum b/gopls/go.sum
index 45070ca..e215e05 100644
--- a/gopls/go.sum
+++ b/gopls/go.sum
@@ -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=
diff --git a/internal/lsp/telemetry/worker/worker.go b/internal/lsp/telemetry/worker/worker.go
new file mode 100644
index 0000000..c72e393
--- /dev/null
+++ b/internal/lsp/telemetry/worker/worker.go
@@ -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
+}