Skip to content

Commit 5f03cca

Browse files
committed
Rewrite coroutine to async def
This allows using async-timeout as a context manager
1 parent 761f605 commit 5f03cca

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

elasticsearch_async/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def __init__(self, host='localhost', port=9200, http_auth=None,
4141
def close(self):
4242
return self.session.close()
4343

44-
@asyncio.coroutine
45-
def perform_request(self, method, url, params=None, body=None, timeout=None, ignore=()):
44+
async def perform_request(self, method, url, params=None, body=None, timeout=None, ignore=()):
4645
url_path = url
4746
if params:
4847
url_path = '%s?%s' % (url, urlencode(params or {}))

elasticsearch_async/transport.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def mark_dead(self, connection):
5858
if self.sniff_on_connection_fail:
5959
self.initiate_sniff()
6060

61-
@asyncio.coroutine
62-
def _get_sniff_data(self, initial=False):
61+
async def _get_sniff_data(self, initial=False):
6362
previous_sniff = self.last_sniff
6463

6564
# reset last_sniff timestamp
@@ -102,8 +101,7 @@ def _get_sniff_data(self, initial=False):
102101
for t in chain(done, tasks):
103102
t.cancel()
104103

105-
@asyncio.coroutine
106-
def sniff_hosts(self, initial=False):
104+
async def sniff_hosts(self, initial=False):
107105
"""
108106
Obtain a list of nodes from the cluster and create a new connection
109107
pool using the information retrieved.
@@ -130,8 +128,7 @@ def sniff_hosts(self, initial=False):
130128
if c not in self.connection_pool.connections:
131129
yield from c.close()
132130

133-
@asyncio.coroutine
134-
def main_loop(self, method, url, params, body, ignore=(), timeout=None):
131+
async def main_loop(self, method, url, params, body, ignore=(), timeout=None):
135132
for attempt in range(self.max_retries + 1):
136133
connection = self.get_connection()
137134

0 commit comments

Comments
 (0)