Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Commit

Permalink
Add a lock util
Browse files Browse the repository at this point in the history
Realized that messages could be sent over the same stream while we're
waiting for a response for the previous message. This is not good. Made
a lock util to help with that.

I see this happening a lot once we start trying to do completion type
items, so that's where I came up with this part.
  • Loading branch information
TJ DeVries committed Dec 21, 2016
1 parent 248b081 commit f410996
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions autoload/langserver/lock.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

function! s:dict_lock() dict
let self.locked = v:true
endfunction

function! s:dict_unlock() dict
let self.locked = v:false
endfunction

function! langserver#lock#semaphore() abort
let l:ret = {}
let l:ret.locked = v:false
let l:ret.lock = function('s:dict_lock')
let l:ret.unlock = function('s:dict_unlock')
return l:ret
endfunction
10 changes: 10 additions & 0 deletions tests/test_lock.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Execute (Test Lock):
let my_lock = langserver#lock#semaphore()

AssertEqual v:false, my_lock.locked

call my_lock.lock()
AssertEqual v:true, my_lock.locked

call my_lock.unlock()
AssertEqual v:false, my_lock.locked

0 comments on commit f410996

Please sign in to comment.