Skip to content

Commit c58d37e

Browse files
committed
Added README.md with usage instructions
1 parent 6bd0a36 commit c58d37e

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from token_system import task_token_guard
2+
13
# TokenGate
24

35
Welcome to the TokenGate repository.
@@ -17,3 +19,58 @@ If you'd like the fuller overview, please start here:
1719
You can also browse the code, run the demos, and see what the idea
1820
is aiming toward. If anything here is useful, interesting, or sparks
1921
an idea, that already makes this project worthwhile.
22+
23+
---
24+
25+
## How to Use (Two Versions, Two Decorators)
26+
> ### Note: Do not attempt to decorate an async fucntion.
27+
>
28+
> #### *The token decorator uses asyncio, but the decorated function itself should be synchronous.*
29+
30+
```python
31+
# -- Python 3.12 -- #
32+
import asyncio
33+
from operations_coordinator import OperationsCoordinator
34+
from token_system import task_token_guard
35+
36+
# CPU only 'weight' options: 'light', 'medium', 'heavy'
37+
# CPU only example:
38+
@task_token_guard(operation_type='string_ops', tags={'weight': 'light'})
39+
def string_operation_task(task_data):
40+
# Simulate a task for threading
41+
return result
42+
43+
# IO writer counts for 'storage_speed':
44+
# 'SLOW' (10 writes), 'MODERATE'(25 writes),
45+
# 'FAST' (50 writes), 'INSANE' (70 writes) <- CAUTION
46+
# CPU and IO combined example:
47+
@task_token_guard(operation_type='data_processing',
48+
tags={'weight': 'heavy', 'storage_speed': 'MODERATE'})
49+
def data_processing_task(task_data):
50+
# Simulate a data processing task
51+
return result
52+
53+
# Usage #1 (optimal - most inclusive):
54+
async def main():
55+
coordinator = OperationsCoordinator()
56+
coordinator.start()
57+
try:
58+
# Normal main body
59+
finally:
60+
coordinator.stop()
61+
62+
if __name__ == "__main__":
63+
asyncio.run(main())
64+
65+
# Usage #2 (simpler - less inclusive):
66+
def main():
67+
coordinator = OperationsCoordinator()
68+
coordinator.start()
69+
try:
70+
# Normal main body
71+
finally:
72+
coordinator.stop()
73+
74+
if __name__ == "__main__":
75+
main()
76+
```

0 commit comments

Comments
 (0)