diff --git a/autoload/langserver/lock.vim b/autoload/langserver/lock.vim new file mode 100644 index 0000000..83c6cdb --- /dev/null +++ b/autoload/langserver/lock.vim @@ -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 diff --git a/tests/test_lock.vader b/tests/test_lock.vader new file mode 100644 index 0000000..b6cdad1 --- /dev/null +++ b/tests/test_lock.vader @@ -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