- # kick off a task to create the connection to MPD.
- asyncio.async(MPDClient.loop.create_connection(
- lambda: MPDProto(future, payload),
- host=self._host,
- port=self._port))
- MPDClient.loop.run_until_complete(future)
- # return the future once completed.
- return future.result()
-
+ # kick off a task to create the connection to MPD
+ coro = self._connect(MPDProto(future, payload, self._cred))
+ asyncio.async(coro)
+ self.futures.append(future)
+ if not self.asio:
+ # return once completed.
+ self.eloop.run_until_complete(future)
+ return future
+ # alternative w/ callback
+ #if not self.asio:
+ # future.add_done_callback(lambda ftr: MPDClient.loop.stop())
+ # self.eloop.run_forever()
+ #return future
+
+ def run(self):
+ if self.futures:
+ self.eloop.run_until_complete(asyncio.gather(*self.futures))
+ self.futures = []
+ else:
+ logging.info('No task found in queue, need to set self.asio?')