{"id":13646371,"url":"https://github.com/chuntaro/emacs-async-await","last_synced_at":"2025-06-20T18:37:32.811Z","repository":{"id":82574670,"uuid":"80717341","full_name":"chuntaro/emacs-async-await","owner":"chuntaro","description":"Async/Await for Emacs","archived":false,"fork":false,"pushed_at":"2022-08-27T04:37:50.000Z","size":24,"stargazers_count":74,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-08T06:42:10.929Z","etag":null,"topics":["async","await","emacs","promise"],"latest_commit_sha":null,"homepage":"","language":"Emacs Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chuntaro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-02-02T11:07:31.000Z","updated_at":"2025-05-10T11:04:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"acf6c31d-4733-40cb-b0e7-85c9810ad95a","html_url":"https://github.com/chuntaro/emacs-async-await","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/chuntaro/emacs-async-await","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuntaro%2Femacs-async-await","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuntaro%2Femacs-async-await/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuntaro%2Femacs-async-await/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuntaro%2Femacs-async-await/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chuntaro","download_url":"https://codeload.github.com/chuntaro/emacs-async-await/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuntaro%2Femacs-async-await/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260998506,"owners_count":23095124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","await","emacs","promise"],"created_at":"2024-08-02T01:02:53.862Z","updated_at":"2025-06-20T18:37:27.798Z","avatar_url":"https://github.com/chuntaro.png","language":"Emacs Lisp","funding_links":[],"categories":["Emacs Lisp"],"sub_categories":[],"readme":"Async/Await for Emacs\n=====================\n\nThis is a simple implementation of Async/Await.  \nInspired by the Async/Await implementation of TypeScript.\n\nThis implementation uses generator.el included in Emacs 25 and [promise.el](https://github.com/chuntaro/emacs-promise).\n\nFor detailed tutorials on its use, see [What about Async/Await?](https://devblogs.microsoft.com/typescript/what-about-async-await/) (TypeScript)\n\nInstallation\n------------\n\nYou can install from MELPA using package.el.  \nThe package name is **async-await**.\n\nUsage\n-----\n\nSee [async-await-examples.el](https://github.com/chuntaro/emacs-async-await/blob/master/examples/async-await-examples.el) for details.\n\n\n```emacs-lisp\n(require 'async-await)\n\n(defun wait-async (n)\n  (promise-new (lambda (resolve _reject)\n                 (run-at-time n\n                              nil\n                              (lambda ()\n                                (funcall resolve n))))))\n\n(async-defun example2 ()\n  (print (await (wait-async 0.5)))\n  (message \"---\")\n\n  (print (await (wait-async 1.0)))\n  (message \"---\")\n\n  (print (await (wait-async 1.5)))\n  (message \"---\")\n\n  (message \"await done\"))\n\n(example2) =\u003e\n\n 0.5\n\n ---\n\n 1.0\n\n ---\n\n 1.5\n\n ---\n await done\n\n The result of the execution is outputted from the top to the bottom\n like the order written in the code. However, asynchronously!\n```\n\nAn example using `url-retrieve 'as a more complicated example.\n\n```emacs-lisp\n(require 'async-await)\n(require 'url-http)\n(require 'xml)\n(require 'dom)\n\n(defun xml-retrieve (url)\n  \"Return `Promise' to resolve with XML object obtained by HTTP request.\"\n  (promise-new\n   (lambda (resolve reject)\n     (url-retrieve url\n                   (lambda (status)\n                     ;; All errors are reliably captured and rejected with appropriate values.\n                     (if (plist-get status :error)\n                         (funcall reject (plist-get status :error))\n                       (condition-case ex\n                           (with-current-buffer (current-buffer)\n                             (if (not (url-http-parse-headers))\n                                 (funcall reject (buffer-string))\n                               (search-forward-regexp \"\\n\\\\s-*\\n\" nil t)\n                               (funcall resolve (xml-parse-region))))\n                         (error (funcall reject ex)))))))))\n\n(defun get-text-first-tag (xml tag)\n  \"Returns the first text that matches TAG in XML.\"\n  (decode-coding-string (dom-text (cl-first (dom-by-tag xml tag)))\n                        'utf-8))\n\n(defun get-short-text-first-tag (xml tag)\n  \"Truncate the text obtained with `get-text-first-tag'.\"\n  (concat (truncate-string-to-width (get-text-first-tag xml tag) 64)\n          \" ...\"))\n\n(defun wait-seconds (seconds fn \u0026rest args)\n  \"Return `Promise' to execute the function after the specified time.\"\n  (promise-new (lambda (resolve _reject)\n                 (run-at-time seconds\n                              nil\n                              (lambda ()\n                                (funcall resolve (apply fn args)))))))\n\n(async-defun example8 ()\n  \"Example using `xml-retrieve'.\"\n  (condition-case reason\n      (let* ((wikipedia-url (concat \"https://en.wikipedia.org/w/api.php\"\n                                    \"?format=xml\u0026action=query\u0026prop=extracts\"\n                                    \"\u0026exintro=\u0026explaintext=\u0026titles=\"))\n             (xml-gnu (await (xml-retrieve (concat wikipedia-url \"GNU\"))))\n             ;; Request after 2 seconds for load reduction.\n             (xml-emacs (await (wait-seconds 2\n                                             #'xml-retrieve\n                                             (concat wikipedia-url \"Emacs\")))))\n        (print (get-short-text-first-tag xml-gnu 'extract))\n        (print (get-short-text-first-tag xml-emacs 'extract)))\n    (error (message \"error: %s\" reason))))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuntaro%2Femacs-async-await","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchuntaro%2Femacs-async-await","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuntaro%2Femacs-async-await/lists"}