def watching(w: bool, watch: Optional[int], max_count: Optional[int] = None, clear: bool = True) -> Iterator[int]:
    """Yield a value every ``watch`` seconds.

    Used to run a command with a watch-based approach.

    :param w: if ``True`` and *watch* is ``None``, then *watch* assumes the value ``2``.
    :param watch: amount of seconds to wait before yielding another value.
    :param max_count: maximum number of yielded values. If ``None`` keep yielding values indefinitely.
    :param clear: if the screen should be cleared out at each iteration.

    :yields: ``0`` each time *watch* seconds have passed.

    :Example:

        >>> len(list(watching(True, 1, 0)))
        1
        >>> len(list(watching(True, 1, 1)))
        2
        >>> len(list(watching(True, None, 0)))
        1
    """
    if w and not watch:
        watch = 2
    if watch and clear:
        click.clear()
    yield 0

    if max_count is not None and max_count < 1:
        return

    counter = 1
    while watch and counter <= (max_count or counter):
        time.sleep(watch)
        counter += 1
        if clear:
            click.clear()
        yield 0
Yield a value every ``watch`` seconds.

    Used to run a command with a watch-based approach.

    :param w: if ``True`` and *watch* is ``None``, then *watch* assumes the value ``2``.
    :param watch: amount of seconds to wait before yielding another value.
    :param max_count: maximum number of yielded values. If ``None`` keep yielding values indefinitely.
    :param clear: if the screen should be cleared out at each iteration.

    :yields: ``0`` each time *watch* seconds have passed.

    :Example:

        >>> len(list(watching(True, 1, 0)))
        1
        >>> len(list(watching(True, 1, 1)))
        2
        >>> len(list(watching(True, None, 0)))
        1
    
patroni/ctl.py