-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
-- import 'config' module | ||
local config = require('smoothcursor.config') | ||
|
||
-- sc_timer -------------------------------------------------------------------- | ||
-- Hold unique uv timer. | ||
local uv = vim.loop | ||
---@class ScTimer | ||
---@field public is_running boolean | ||
---@field public timer unknown | ||
local ScTimer = {} | ||
ScTimer.__index = ScTimer | ||
|
||
local sc_timer = { | ||
is_running = false, | ||
timer = uv.new_timer(), | ||
} | ||
|
||
-- post if timer is stop | ||
--- Post if timer is stopped. | ||
---@param func function | ||
function sc_timer:post(func) | ||
if self.is_runnig then | ||
function ScTimer:post(func) | ||
if self.is_running then | ||
return | ||
end | ||
uv.timer_start(self.timer, 0, config.config.intervals, vim.schedule_wrap(func)) | ||
vim.loop.timer_start(self.timer, 0, config.config.intervals, vim.schedule_wrap(func)) | ||
self.is_running = true | ||
end | ||
|
||
function sc_timer:abort() | ||
--- Abort the timer. | ||
function ScTimer:abort() | ||
self.timer:stop() | ||
self.is_running = false | ||
end | ||
|
||
-- Initialize ScTimer object. | ||
---@return ScTimer | ||
local function newScTimer() | ||
local self = setmetatable({}, ScTimer) | ||
self.is_running = false | ||
self.timer = vim.uv.new_timer() | ||
return self | ||
end | ||
|
||
---@type ScTimer | ||
local sc_timer = newScTimer() | ||
|
||
return { | ||
sc_timer = sc_timer, | ||
} |