{"componentChunkName":"component---node-modules-smooth-doc-src-templates-doc-js","path":"/docs/blocking/","result":{"data":{"mdx":{"fields":{"pageType":"doc","title":"Asynchronous Programming","editLink":""},"body":"var _excluded = [\"components\"];\nfunction _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {\n  \"title\": \"Asynchronous Programming\",\n  \"section\": \"Quick Docs\",\n  \"order\": 2\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"Imagine that you're coding a Discord bot and every time somebody uses a command, you need to get some information from a database. But there's a catch: the database servers are acting up today and take a whole 10 seconds to respond. If you do \", mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"not\"), \" use asynchronous methods, your whole bot will stop running until it gets a response from the database. How do you fix this? Asynchronous programming.\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"What is asynchronous programming?\"), \"\\nAn asynchronous program utilises the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"async\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"await\"), \" keywords. An asynchronous program pauses what it's doing and does something else whilst it waits for some third-party service to complete whatever it's supposed to do. Any code within an \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"async\"), \" context manager or function marked with the \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"await\"), \" keyword indicates to Python, that whilst this operation is being completed, it can do something else. For example:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-py\"\n  }, \"import discord\\n\\n# Bunch of bot code\\n\\nasync def ping(ctx):\\n    await ctx.send(\\\"Pong!\\\")\\n\")), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"What does the term \\\"blocking\\\" mean?\"), \"\\nA blocking operation is wherever you do something without \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"await\"), \"ing it. This tells Python that this step must be completed before it can do anything else. Common examples of blocking operations, as simple as they may seem, include: outputting text, adding two numbers and appending an item onto a list. Most common Python libraries have an asynchronous version available to use in asynchronous contexts.\"), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, mdx(\"inlineCode\", {\n    parentName: \"strong\"\n  }, \"async\"), \" libraries\")), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"The standard async library - \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"asyncio\")), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Asynchronous web requests - \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"aiohttp\")), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Talking to PostgreSQL asynchronously - \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"asyncpg\")), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"MongoDB interactions asynchronously - \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"motor\")), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Check out \", mdx(\"a\", {\n    parentName: \"li\",\n    \"href\": \"https://github.com/timofurrer/awesome-asyncio\"\n  }, \"this\"), \" list for even more!\")));\n}\n;\nMDXContent.isMDXComponent = true;","tableOfContents":{}}},"pageContext":{"id":"cb9bb1db-211d-541b-9fc7-e74d8cae1669"}},"staticQueryHashes":["1022386572","1122327541","1339625561","2140385554","3442269102","3597609067"]}