Skip to content
Discussion options

You must be logged in to vote

The program work as expected. The async iterator waits for an unlimited time, if no message were sent from the server to your client.

Some example code:

import sys
import aiohttp
import asyncio
import json


WS_URL = "wss://echo.websocket.org/"


class AsyncTimeoutIterator:
    """
    Simple implementation of AsyncTimeoutIterator.
    
    The class iterates over an async generator and
    if it takes longer than the timeout, the iteration is stopped.
    """
    def __init__(self, async_gen, timeout):
        self.gen = async_gen
        self.timeout = timeout
    
    # should be a sync function?
    def __aiter__(self):
        return self
    
    # async function for the next item
    

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@LaySoft
Comment options

Answer selected by LaySoft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants