mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Issue #27041: asyncio: Add loop.create_future method
This commit is contained in:
		
							parent
							
								
									7ed7ce6ee7
								
							
						
					
					
						commit
						7661db6228
					
				
					 14 changed files with 55 additions and 39 deletions
				
			
		| 
						 | 
				
			
			@ -209,7 +209,7 @@ class Server(events.AbstractServer):
 | 
			
		|||
    def wait_closed(self):
 | 
			
		||||
        if self.sockets is None or self._waiters is None:
 | 
			
		||||
            return
 | 
			
		||||
        waiter = futures.Future(loop=self._loop)
 | 
			
		||||
        waiter = self._loop.create_future()
 | 
			
		||||
        self._waiters.append(waiter)
 | 
			
		||||
        yield from waiter
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -243,6 +243,10 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
			
		|||
                % (self.__class__.__name__, self.is_running(),
 | 
			
		||||
                   self.is_closed(), self.get_debug()))
 | 
			
		||||
 | 
			
		||||
    def create_future(self):
 | 
			
		||||
        """Create a Future object attached to the loop."""
 | 
			
		||||
        return futures.Future(loop=self)
 | 
			
		||||
 | 
			
		||||
    def create_task(self, coro):
 | 
			
		||||
        """Schedule a coroutine object.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -536,7 +540,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
			
		|||
            assert not args
 | 
			
		||||
            assert not isinstance(func, events.TimerHandle)
 | 
			
		||||
            if func._cancelled:
 | 
			
		||||
                f = futures.Future(loop=self)
 | 
			
		||||
                f = self.create_future()
 | 
			
		||||
                f.set_result(None)
 | 
			
		||||
                return f
 | 
			
		||||
            func, args = func._callback, func._args
 | 
			
		||||
| 
						 | 
				
			
			@ -579,7 +583,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
			
		|||
                    family=0, type=0, proto=0, flags=0):
 | 
			
		||||
        info = _ipaddr_info(host, port, family, type, proto)
 | 
			
		||||
        if info is not None:
 | 
			
		||||
            fut = futures.Future(loop=self)
 | 
			
		||||
            fut = self.create_future()
 | 
			
		||||
            fut.set_result([info])
 | 
			
		||||
            return fut
 | 
			
		||||
        elif self._debug:
 | 
			
		||||
| 
						 | 
				
			
			@ -720,7 +724,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
			
		|||
    def _create_connection_transport(self, sock, protocol_factory, ssl,
 | 
			
		||||
                                     server_hostname):
 | 
			
		||||
        protocol = protocol_factory()
 | 
			
		||||
        waiter = futures.Future(loop=self)
 | 
			
		||||
        waiter = self.create_future()
 | 
			
		||||
        if ssl:
 | 
			
		||||
            sslcontext = None if isinstance(ssl, bool) else ssl
 | 
			
		||||
            transport = self._make_ssl_transport(
 | 
			
		||||
| 
						 | 
				
			
			@ -840,7 +844,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
			
		|||
                raise exceptions[0]
 | 
			
		||||
 | 
			
		||||
        protocol = protocol_factory()
 | 
			
		||||
        waiter = futures.Future(loop=self)
 | 
			
		||||
        waiter = self.create_future()
 | 
			
		||||
        transport = self._make_datagram_transport(
 | 
			
		||||
            sock, protocol, r_addr, waiter)
 | 
			
		||||
        if self._debug:
 | 
			
		||||
| 
						 | 
				
			
			@ -979,7 +983,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
			
		|||
    @coroutine
 | 
			
		||||
    def connect_read_pipe(self, protocol_factory, pipe):
 | 
			
		||||
        protocol = protocol_factory()
 | 
			
		||||
        waiter = futures.Future(loop=self)
 | 
			
		||||
        waiter = self.create_future()
 | 
			
		||||
        transport = self._make_read_pipe_transport(pipe, protocol, waiter)
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
| 
						 | 
				
			
			@ -996,7 +1000,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
			
		|||
    @coroutine
 | 
			
		||||
    def connect_write_pipe(self, protocol_factory, pipe):
 | 
			
		||||
        protocol = protocol_factory()
 | 
			
		||||
        waiter = futures.Future(loop=self)
 | 
			
		||||
        waiter = self.create_future()
 | 
			
		||||
        transport = self._make_write_pipe_transport(pipe, protocol, waiter)
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue