2021-01-05 10:22:48 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
import threading
|
2022-01-24 08:46:32 +00:00
|
|
|
from typing import Optional
|
2021-01-05 10:22:48 +00:00
|
|
|
|
|
|
|
from . import shared_abstract
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleSharedDict(shared_abstract.SharedDict):
|
|
|
|
|
2021-12-27 08:26:22 +00:00
|
|
|
__slots__ = ('d',)
|
2021-01-05 10:22:48 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.d = {}
|
|
|
|
|
2022-01-24 08:46:32 +00:00
|
|
|
def get_int(self, key: str) -> Optional[int]:
|
2021-01-05 10:22:48 +00:00
|
|
|
return self.d.get(key, None)
|
|
|
|
|
2022-01-24 08:46:32 +00:00
|
|
|
def set_int(self, key: str, value: int):
|
2021-01-05 10:22:48 +00:00
|
|
|
self.d[key] = value
|
|
|
|
|
2022-01-24 08:46:32 +00:00
|
|
|
def get_str(self, key: str) -> Optional[str]:
|
2021-01-05 10:22:48 +00:00
|
|
|
return self.d.get(key, None)
|
|
|
|
|
2022-01-24 08:46:32 +00:00
|
|
|
def set_str(self, key: str, value: str):
|
2021-01-05 10:22:48 +00:00
|
|
|
self.d[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
def schedule(delay, func, *args):
|
|
|
|
def call_later():
|
|
|
|
t = threading.Timer(delay, wrapper)
|
|
|
|
t.daemon = True
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
def wrapper():
|
|
|
|
call_later()
|
|
|
|
func(*args)
|
|
|
|
|
|
|
|
call_later()
|
2021-01-13 13:07:39 +00:00
|
|
|
return True
|