Make notifee functions all async
This commit is contained in:
parent
5a4af0c81c
commit
0d2aa3f5b1
|
@ -1,44 +1,45 @@
|
|||
import asyncio
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
class INotifee(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def opened_stream(self, network, stream):
|
||||
async def opened_stream(self, network, stream):
|
||||
"""
|
||||
:param network: network the stream was opened on
|
||||
:param stream: stream that was opened
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def closed_stream(self, network, stream):
|
||||
async def closed_stream(self, network, stream):
|
||||
"""
|
||||
:param network: network the stream was closed on
|
||||
:param stream: stream that was closed
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def connected(self, network, conn):
|
||||
async def connected(self, network, conn):
|
||||
"""
|
||||
:param network: network the connection was opened on
|
||||
:param conn: connection that was opened
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def disconnected(self, network, conn):
|
||||
async def disconnected(self, network, conn):
|
||||
"""
|
||||
:param network: network the connection was closed on
|
||||
:param conn: connection that was closed
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def listen(self, network, multiaddr):
|
||||
async def listen(self, network, multiaddr):
|
||||
"""
|
||||
:param network: network the listener is listening on
|
||||
:param multiaddr: multiaddress listener is listening on
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def listen_close(self, network, multiaddr):
|
||||
async def listen_close(self, network, multiaddr):
|
||||
"""
|
||||
:param network: network the connection was opened on
|
||||
:param multiaddr: multiaddress listener is no longer listening on
|
||||
|
|
|
@ -76,7 +76,7 @@ class Swarm(INetwork):
|
|||
|
||||
# Call notifiers since event occurred
|
||||
for notifee in self.notifees:
|
||||
notifee.connected(self, muxed_conn)
|
||||
await notifee.connected(self, muxed_conn)
|
||||
|
||||
return muxed_conn
|
||||
|
||||
|
@ -110,7 +110,7 @@ class Swarm(INetwork):
|
|||
|
||||
# Call notifiers since event occurred
|
||||
for notifee in self.notifees:
|
||||
notifee.opened_stream(self, net_stream)
|
||||
await notifee.opened_stream(self, net_stream)
|
||||
|
||||
return net_stream
|
||||
|
||||
|
@ -151,7 +151,7 @@ class Swarm(INetwork):
|
|||
|
||||
# Call notifiers since event occurred
|
||||
for notifee in self.notifees:
|
||||
notifee.connected(self, muxed_conn)
|
||||
await notifee.connected(self, muxed_conn)
|
||||
|
||||
try:
|
||||
# Success
|
||||
|
@ -161,7 +161,7 @@ class Swarm(INetwork):
|
|||
|
||||
# Call notifiers since event occurred
|
||||
for notifee in self.notifees:
|
||||
notifee.listen(self, multiaddr)
|
||||
await notifee.listen(self, multiaddr)
|
||||
|
||||
return True
|
||||
except IOError:
|
||||
|
|
|
@ -28,23 +28,23 @@ class MyNotifee(INotifee):
|
|||
self.events = events
|
||||
self.val_to_append_to_event = val_to_append_to_event
|
||||
|
||||
def opened_stream(self, network, stream):
|
||||
async def opened_stream(self, network, stream):
|
||||
self.events.append(["opened_stream" + \
|
||||
self.val_to_append_to_event, stream])
|
||||
|
||||
def closed_stream(self, network, stream):
|
||||
async def closed_stream(self, network, stream):
|
||||
pass
|
||||
|
||||
def connected(self, network, conn):
|
||||
async def connected(self, network, conn):
|
||||
self.events.append("connected" + self.val_to_append_to_event)
|
||||
|
||||
def disconnected(self, network, conn):
|
||||
async def disconnected(self, network, conn):
|
||||
pass
|
||||
|
||||
def listen(self, network, multiaddr):
|
||||
async def listen(self, network, multiaddr):
|
||||
pass
|
||||
|
||||
def listen_close(self, network, multiaddr):
|
||||
async def listen_close(self, network, multiaddr):
|
||||
pass
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
Loading…
Reference in New Issue
Block a user