forked from agiresearch/AIOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.py
More file actions
33 lines (24 loc) · 753 Bytes
/
Copy pathstate.py
File metadata and controls
33 lines (24 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import Any, Callable
class GlobalState:
def __init__(self):
self._attribute = None
self._callback = None
@property
def attribute(self):
return self._attribute
@attribute.setter
def attribute(self, value):
self._attribute = value
if self._callback:
self._callback(value)
def set_callback(self, callback_func):
self._callback = callback_func
def useGlobalState():
state = GlobalState()
def getGlobalState():
return state.attribute
def setCallback(cb: Callable[[Any],Any]):
state.set_callback(cb)
def setGlobalState(value: Any):
state.attribute = value
return getGlobalState, setGlobalState, setCallback