asyncio: use loop.create_future() instead of asyncio.Future()
from https://docs.python.org/3.10/library/asyncio-future.html#asyncio.Future : > the recommended way to create a Future object is to call loop.create_future(). > This way alternative event loop implementations can inject their own optimized implementations of a Future object.
This commit is contained in:
@@ -363,7 +363,7 @@ class Interface(Logger):
|
||||
LOGGING_SHORTCUT = 'i'
|
||||
|
||||
def __init__(self, *, network: 'Network', server: ServerAddr, proxy: Optional[dict]):
|
||||
self.ready = asyncio.Future()
|
||||
self.ready = network.asyncio_loop.create_future()
|
||||
self.got_disconnected = asyncio.Event()
|
||||
self.server = server
|
||||
Logger.__init__(self)
|
||||
|
||||
@@ -79,21 +79,22 @@ class Peer(Logger):
|
||||
transport: LNTransportBase,
|
||||
*, is_channel_backup= False):
|
||||
|
||||
self.lnworker = lnworker
|
||||
self.network = lnworker.network
|
||||
self.asyncio_loop = self.network.asyncio_loop
|
||||
self.is_channel_backup = is_channel_backup
|
||||
self._sent_init = False # type: bool
|
||||
self._received_init = False # type: bool
|
||||
self.initialized = asyncio.Future()
|
||||
self.initialized = self.asyncio_loop.create_future()
|
||||
self.got_disconnected = asyncio.Event()
|
||||
self.querying = asyncio.Event()
|
||||
self.transport = transport
|
||||
self.pubkey = pubkey # remote pubkey
|
||||
self.lnworker = lnworker
|
||||
self.privkey = self.transport.privkey # local privkey
|
||||
self.features = self.lnworker.features # type: LnFeatures
|
||||
self.their_features = LnFeatures(0) # type: LnFeatures
|
||||
self.node_ids = [self.pubkey, privkey_to_pubkey(self.privkey)]
|
||||
assert self.node_ids[0] != self.node_ids[1]
|
||||
self.network = lnworker.network
|
||||
self.ping_time = 0
|
||||
self.reply_channel_range = asyncio.Queue()
|
||||
# gossip uses a single queue to preserve message order
|
||||
@@ -104,7 +105,7 @@ class Peer(Logger):
|
||||
self.funding_signed_sent = set() # for channels in PREOPENING
|
||||
self.shutdown_received = {} # chan_id -> asyncio.Future()
|
||||
self.announcement_signatures = defaultdict(asyncio.Queue)
|
||||
self.channel_reestablish_msg = defaultdict(asyncio.Future)
|
||||
self.channel_reestablish_msg = defaultdict(self.asyncio_loop.create_future)
|
||||
self.orphan_channel_updates = OrderedDict() # type: OrderedDict[ShortChannelID, dict]
|
||||
Logger.__init__(self)
|
||||
self.taskgroup = OldTaskGroup()
|
||||
@@ -1289,7 +1290,7 @@ class Peer(Logger):
|
||||
chan.config[LOCAL].was_announced = True
|
||||
self.lnworker.save_channel(chan)
|
||||
coro = self.handle_announcements(chan)
|
||||
asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
|
||||
asyncio.run_coroutine_threadsafe(coro, self.asyncio_loop)
|
||||
|
||||
@log_exceptions
|
||||
async def handle_announcements(self, chan: Channel):
|
||||
@@ -1874,7 +1875,7 @@ class Peer(Logger):
|
||||
@log_exceptions
|
||||
async def close_channel(self, chan_id: bytes):
|
||||
chan = self.channels[chan_id]
|
||||
self.shutdown_received[chan_id] = asyncio.Future()
|
||||
self.shutdown_received[chan_id] = self.asyncio_loop.create_future()
|
||||
await self.send_shutdown(chan)
|
||||
payload = await self.shutdown_received[chan_id]
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user