Timeout - asimpy

Skip to content

# Timeout

Wait for a simulated time to pass.

## `Timeout`

Bases: `Event`

Timeout event for sleeping.

Source code in `src/asimpy/timeout.py`

    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    class Timeout(Event):
        """Timeout event for sleeping."""

        def __init__(self, env: "Environment", delay: float | int):
            """
            Construct timeout.

            Args:
                env: simulation environment.
                delay: how long to wait.

            Raises:
                ValueError: for invalid `delay`.
            """
            if delay < 0:
                raise ValueError(f"timeout delay must be non-negative, got {delay}")
            super().__init__(env)
            env.schedule(env.now + delay, self._fire)

        def _fire(self):
            """Handle cancellation case."""
            if self._cancelled:
                return _NO_TIME
            self.succeed()

### `__init__(env, delay)`

Construct timeout.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`env` | `Environment` | simulation environment. | required
`delay` | `float | int` | how long to wait. | required

Raises:

Type | Description
--- | ---
`ValueError` | for invalid `delay`.

Source code in `src/asimpy/timeout.py`

    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    def __init__(self, env: "Environment", delay: float | int):
        """
        Construct timeout.

        Args:
            env: simulation environment.
            delay: how long to wait.

        Raises:
            ValueError: for invalid `delay`.
        """
        if delay < 0:
            raise ValueError(f"timeout delay must be non-negative, got {delay}")
        super().__init__(env)
        env.schedule(env.now + delay, self._fire)