Skip to content

Commit

Permalink
[QI2-1119] implemented more compact code
Browse files Browse the repository at this point in the history
  • Loading branch information
napocornejo committed Oct 21, 2024
1 parent ea8aeb4 commit d6e4fbb
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions qiskit_quantuminspire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ def is_coupling_map_complete(coupling_map: CouplingMap) -> bool:

def run_async(async_function: Coroutine[Any, Any, Any]) -> Any:
try:
loop = asyncio.get_running_loop()
except RuntimeError: # 'RuntimeError: There is no current event loop...'
loop = None

if loop and loop.is_running():
_ = asyncio.get_running_loop()
with concurrent.futures.ThreadPoolExecutor() as executor:
future = executor.submit(asyncio.run, async_function)
return future.result()
else:
return executor.submit(asyncio.run, async_function).result()
except RuntimeError:
return asyncio.run(async_function)

0 comments on commit d6e4fbb

Please sign in to comment.