Skip to content

Commit a01cf52

Browse files
committed
slightly refactored syncer
1 parent ee6b06e commit a01cf52

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

Diff for: handler/syncer.go

+16-20
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,22 @@ type AsyncHandler struct {
2727
func (ah AsyncHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
2828
needsWriteLock := req.Method == "textDocument/didOpen" || req.Method == "textDocument/didChange"
2929
if needsWriteLock {
30-
ah.synchronizer.FileMux.Lock()
31-
if enableLogging {
32-
log.Println("Message processing locked for", req.Method)
33-
}
34-
go ah.runWrite(ctx, conn, req)
30+
go func() {
31+
ah.synchronizer.FileMux.Lock()
32+
defer ah.synchronizer.FileMux.Unlock()
33+
if enableLogging {
34+
log.Println("Message processing locked for", req.Method)
35+
}
36+
ah.handler.Handle(ctx, conn, req)
37+
if enableLogging {
38+
log.Println("Message processing unlocked for", req.Method)
39+
}
40+
}()
3541
} else {
36-
ah.synchronizer.FileMux.RLock()
37-
go ah.runRead(ctx, conn, req)
38-
}
39-
}
40-
41-
func (ah AsyncHandler) runRead(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
42-
defer ah.synchronizer.FileMux.RUnlock()
43-
ah.handler.Handle(ctx, conn, req)
44-
}
45-
46-
func (ah AsyncHandler) runWrite(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) {
47-
defer ah.synchronizer.FileMux.Unlock()
48-
ah.handler.Handle(ctx, conn, req)
49-
if enableLogging {
50-
log.Println("Message processing unlocked for", req.Method)
42+
go func() {
43+
ah.synchronizer.FileMux.RLock()
44+
ah.handler.Handle(ctx, conn, req)
45+
ah.synchronizer.FileMux.RUnlock()
46+
}()
5147
}
5248
}

0 commit comments

Comments
 (0)