mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-28 18:21:42 +00:00
Utils: Remove unused defer utils
These did not work anyways Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
@@ -87,53 +87,3 @@ def unwrap_optional_type(type_hint) -> Type:
|
|||||||
|
|
||||||
return type_hint
|
return type_hint
|
||||||
|
|
||||||
|
|
||||||
def with_defer(func):
|
|
||||||
"""
|
|
||||||
Decorator for a go-style defer
|
|
||||||
"""
|
|
||||||
|
|
||||||
def wrapper(*args, **kwargs):
|
|
||||||
deferred_calls = []
|
|
||||||
|
|
||||||
# This 'defer' function is what you'll call inside your decorated function
|
|
||||||
def defer(fn, *fn_args, **fn_kwargs):
|
|
||||||
deferred_calls.append((fn, fn_args, fn_kwargs))
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Inject 'defer' into the kwargs of the original function
|
|
||||||
return func(*args, defer=defer, **kwargs)
|
|
||||||
finally:
|
|
||||||
# After the original function finishes (or raises), run deferred calls
|
|
||||||
for fn, fn_args, fn_kwargs in reversed(deferred_calls):
|
|
||||||
fn(*fn_args, **fn_kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
def with_defer_async(func):
|
|
||||||
"""
|
|
||||||
Decorator for running async functions in go-style defer blocks
|
|
||||||
"""
|
|
||||||
|
|
||||||
async def wrapper(*args, **kwargs):
|
|
||||||
deferred_calls = []
|
|
||||||
|
|
||||||
# This 'defer' function is what you'll call inside your decorated function
|
|
||||||
def defer(fn, *fn_args, **fn_kwargs):
|
|
||||||
deferred_calls.append((fn, fn_args, fn_kwargs))
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Inject 'defer' into the kwargs of the original function
|
|
||||||
return await func(*args, defer=defer, **kwargs)
|
|
||||||
finally:
|
|
||||||
# After the original function finishes (or raises), run deferred calls
|
|
||||||
for fn, fn_args, fn_kwargs in reversed(deferred_calls):
|
|
||||||
if inspect.iscoroutinefunction(fn):
|
|
||||||
await fn(*fn_args, **fn_kwargs)
|
|
||||||
elif inspect.iscoroutine(fn):
|
|
||||||
await fn
|
|
||||||
else:
|
|
||||||
fn(*fn_args, **fn_kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|||||||
Reference in New Issue
Block a user