Index: third_party/mojo/src/mojo/public/go/bindings/router.go |
diff --git a/third_party/mojo/src/mojo/public/go/bindings/router.go b/third_party/mojo/src/mojo/public/go/bindings/router.go |
index 84a5d3c0dbd0f78d32327e2b57d2ed8588610d0b..64849455103ac7b01c67330967999dbdda219886 100644 |
--- a/third_party/mojo/src/mojo/public/go/bindings/router.go |
+++ b/third_party/mojo/src/mojo/public/go/bindings/router.go |
@@ -120,6 +120,8 @@ type Router struct { |
// Channel to communicate with worker. |
requestChan chan<- routeRequest |
+ // Makes sure that the done channel is closed once. |
+ closeOnce sync.Once |
// Channel to stop the worker. |
done chan<- struct{} |
} |
@@ -147,10 +149,11 @@ func NewRouter(handle system.MessagePipeHandle, waiter AsyncWaiter) *Router { |
} |
// Close closes the router and the underlying message pipe. All new incoming |
-// requests are returned with an error. Panics if you try to close the router |
-// more than once. |
+// requests are returned with an error. |
func (r *Router) Close() { |
- close(r.done) |
+ r.closeOnce.Do(func() { |
+ close(r.done) |
+ }) |
} |
// Accept sends a message to the message pipe. The message should have a |