All Projects → chuntaro → Emacs Async Await

chuntaro / Emacs Async Await

Async/Await for Emacs

Projects that are alternatives of or similar to Emacs Async Await

Wx Promise Pro
✨强大、优雅的微信小程序异步库🚀
Stars: ✭ 762 (+1521.28%)
Mutual labels:  async, promise, await
Await Of
await wrapper for easier errors handling without try-catch
Stars: ✭ 240 (+410.64%)
Mutual labels:  async, promise, await
Awaitkit
The ES8 Async/Await control flow for Swift
Stars: ✭ 709 (+1408.51%)
Mutual labels:  async, promise, await
Ws Promise Client
PROJECT MOVED: https://github.com/kdex/ws-promise
Stars: ✭ 6 (-87.23%)
Mutual labels:  async, promise, await
P Map
Map over promises concurrently
Stars: ✭ 639 (+1259.57%)
Mutual labels:  async, promise, await
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (+617.02%)
Mutual labels:  async, promise, await
Breeze
Javascript async flow control manager
Stars: ✭ 38 (-19.15%)
Mutual labels:  async, promise, await
Asyncawaitbestpractices
Extensions for System.Threading.Tasks.Task and System.Threading.Tasks.ValueTask
Stars: ✭ 693 (+1374.47%)
Mutual labels:  async, await
Blockly Gamepad
A Blockly extension designed to develop games (made with love ❤)
Stars: ✭ 18 (-61.7%)
Mutual labels:  async, await
Await Handler
Basic wrapper for await that allows handling of errors without try/catch blocks
Stars: ✭ 13 (-72.34%)
Mutual labels:  promise, await
Micro Router
🚉 A tiny and functional router for Zeit's Micro
Stars: ✭ 621 (+1221.28%)
Mutual labels:  async, await
Then
🎬 Tame async code with battle-tested promises
Stars: ✭ 908 (+1831.91%)
Mutual labels:  async, promise
Koahub Demo
koahub+async/await+mysql
Stars: ✭ 15 (-68.09%)
Mutual labels:  async, await
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+1368.09%)
Mutual labels:  async, await
Nodespider
[DEPRECATED] Simple, flexible, delightful web crawler/spider package
Stars: ✭ 33 (-29.79%)
Mutual labels:  async, promise
Vue Loadable
⏳ Improve your loading state control with pretty simple methods and helpers.
Stars: ✭ 23 (-51.06%)
Mutual labels:  async, promise
Csp
Communicating Sequential Processes in JavaScript
Stars: ✭ 33 (-29.79%)
Mutual labels:  async, await
Node Qiniu Sdk
七牛云SDK,使用 ES2017 async functions 来操作七牛云,接口名称与官方接口对应,轻松上手,文档齐全
Stars: ✭ 44 (-6.38%)
Mutual labels:  async, promise
Posterus
Composable async primitives with cancelation, control over scheduling, and coroutines. Superior replacement for JS Promises.
Stars: ✭ 536 (+1040.43%)
Mutual labels:  async, promise
Emacs Ng
A new approach to Emacs - Including TypeScript, Threading, Async I/O, and WebRender.
Stars: ✭ 525 (+1017.02%)
Mutual labels:  async, emacs

Async/Await for Emacs

This is a simple implementation of Async/Await.
Inspired by the Async/Await implementation of TypeScript.

This implementation uses generator.el included in Emacs 25 and promise.el.

For detailed tutorials on its use, see What about Async/Await? (TypeScript)

Installation

You can install from MELPA using package.el.
The package name is async-await.

Usage

See async-await-examples.el for details.

(require 'async-await)

(defun wait-async (n)
  (promise-new (lambda (resolve _reject)
                 (run-at-time n
                              nil
                              (lambda ()
                                (funcall resolve n))))))

(async-defun example2 ()
  (print (await (wait-async 0.5)))
  (message "---")

  (print (await (wait-async 1.0)))
  (message "---")

  (print (await (wait-async 1.5)))
  (message "---")

  (message "await done"))

(example2) =>

 0.5

 ---

 1.0

 ---

 1.5

 ---
 await done

 The result of the execution is outputted from the top to the bottom
 like the order written in the code. However, asynchronously!

An example using `url-retrieve 'as a more complicated example.

(require 'async-await)
(require 'url-http)
(require 'xml)
(require 'dom)

(defun xml-retrieve (url)
  "Return `Promise' to resolve with XML object obtained by HTTP request."
  (promise-new
   (lambda (resolve reject)
     (url-retrieve url
                   (lambda (status)
                     ;; All errors are reliably captured and rejected with appropriate values.
                     (if (plist-get status :error)
                         (funcall reject (plist-get status :error))
                       (condition-case ex
                           (with-current-buffer (current-buffer)
                             (if (not (url-http-parse-headers))
                                 (funcall reject (buffer-string))
                               (search-forward-regexp "\n\\s-*\n" nil t)
                               (funcall resolve (xml-parse-region))))
                         (error (funcall reject ex)))))))))

(defun get-text-first-tag (xml tag)
  "Returns the first text that matches TAG in XML."
  (decode-coding-string (dom-text (cl-first (dom-by-tag xml tag)))
                        'utf-8))

(defun get-short-text-first-tag (xml tag)
  "Truncate the text obtained with `get-text-first-tag'."
  (concat (truncate-string-to-width (get-text-first-tag xml tag) 64)
          " ..."))

(defun wait-seconds (seconds fn &rest args)
  "Return `Promise' to execute the function after the specified time."
  (promise-new (lambda (resolve _reject)
                 (run-at-time seconds
                              nil
                              (lambda ()
                                (funcall resolve (apply fn args)))))))

(async-defun example8 ()
  "Example using `xml-retrieve'."
  (condition-case reason
      (let* ((wikipedia-url (concat "https://en.wikipedia.org/w/api.php"
                                    "?format=xml&action=query&prop=extracts"
                                    "&exintro=&explaintext=&titles="))
             (xml-gnu (await (xml-retrieve (concat wikipedia-url "GNU"))))
             ;; Request after 2 seconds for load reduction.
             (xml-emacs (await (wait-seconds 2
                                             #'xml-retrieve
                                             (concat wikipedia-url "Emacs")))))
        (print (get-short-text-first-tag xml-gnu 'extract))
        (print (get-short-text-first-tag xml-emacs 'extract)))
    (error (message "error: %s" reason))))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].