From 016491fa1fba2bc866eddec39ea4844efd2cc2c0 Mon Sep 17 00:00:00 2001 From: 4n0n <4n0n@tinkr.site> Date: Thu, 2 Feb 2023 10:20:18 -0600 Subject: [PATCH] Cacheable emmy lua --- src/Cacheable/Cacheable.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Cacheable/Cacheable.lua b/src/Cacheable/Cacheable.lua index f4faf8a..3dd0214 100644 --- a/src/Cacheable/Cacheable.lua +++ b/src/Cacheable/Cacheable.lua @@ -30,11 +30,14 @@ function Cacheable:__index(k) end -- When the object is accessed return the value +---@return string function Cacheable:__tostring() return "Bastion.__Cacheable(" .. tostring(self.value) .. ")" end -- Create +---@param value any +---@param cb fun():any function Cacheable:New(value, cb) local self = setmetatable({}, Cacheable) @@ -48,6 +51,7 @@ function Cacheable:New(value, cb) end -- Try to update the value +---@return nil function Cacheable:TryUpdate() if self.cache:IsCached("value") then self.value = self.callback() @@ -55,16 +59,19 @@ function Cacheable:TryUpdate() end -- Update the value +---@return nil function Cacheable:Update() self.value = self.callback() end -- Set a new value +---@param value any function Cacheable:Set(value) self.value = value end -- Set a new callback +---@param cb fun():any function Cacheable:SetCallback(cb) self.callback = cb end