1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Helpers for handling of timeouts for request.
 
  10 from typing import Union, Optional
 
  15     """ A class that provides helper functions to ensure a given timeout
 
  16         is respected. Can only be used from coroutines.
 
  18     def __init__(self, timeout: Optional[Union[int, float]]) -> None:
 
  19         self.abs = None if timeout is None else asyncio.get_running_loop().time() + timeout
 
  21     def is_elapsed(self) -> bool:
 
  22         """ Check if the timeout has already passed.
 
  24         return (self.abs is not None) and (asyncio.get_running_loop().time() >= self.abs)