Solución
solution.tsTypeScript
class ManagedResource:
def __init__(self, value):
self.value = value
self.entered = False
self.exited = False
def __enter__(self):
# Marca el recurso como activo y retorna self
self.entered = True
return self
def __exit__(self, exc_type, exc_val, exc_tb):
# Marca el recurso como inactivo
if self.entered == True:
self.exited = True
return False
def use_managed_resource(value) -> dict:
# Usa ManagedResource como context manager y retorna el estado del ciclo de vida
with ManagedResource(value) as r:
pass
return {"entered": r.entered, "value": r.value, "exited": r.exited}0respuestas