{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# top-level await\n",
    "\n",
    "this feature is tested separately because it requires a non-standard invocationin `exec_module`.\n",
    "\n",
    "## why\n",
    "\n",
    "[top-level auto-await](https://ipython.readthedocs.io/en/stable/interactive/autoawait.html) behavior is a feature of `IPython`, and [nodejs](https://maximorlov.com/tips/top-level-await-in-nodejs/). `importnb` supports top-level awaits by implicitly running coroutines in the current event loop.s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from contextlib import asynccontextmanager\n",
    "async def async_function(): return 10\n",
    "@asynccontextmanager\n",
    "async def async_context_context_manager():\n",
    "    yield async_function\n",
    "awaited_data = await async_function()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[⚠](https://gist.github.com/Rich-Harris/0b6f317657f5167663b493c722647221 \"top level async is a foot gun\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:root] *",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "vscode": {
   "interpreter": {
    "hash": "fe3da9b82b3647283ed4a64afb514c08b1aa39774194ba3fa7469a9333d7260c"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
