GithubHelp home page GithubHelp logo

yasync's Introduction

yasync - Yet another async/await for Nim Build Status

Requires nim devel or 2.0.

  • Semantics is very close to that of Nim's std async, await and Future[T].
  • await operation doesn't cause any heap allocations (except calling manually-async functions, async closures, and (mutually) recursive calls).
  • callSoon is not used and async code is guaranteed to run atomically between awaits across call boundaries (TODO: maybe add an example)
  • Function return type is written as T, then async transforms it to Future[T] implicitly.
  • Provides optional compatibility layer for interop with existing asyncdispatch (and TODO: chronos) code. Example. The library itself is completely dispatcher agnostic, and doesn't depend on neither asyncdispatch, nor chronos.

This library introduces async, await and Future[T] similar in semantics to Nim's native ones, but implements an optimization to avoid heap allocations. Consider the following sample:

proc sleep(ms: int): Future[void] = ... # Let's assume this function doesn't allocate

proc foo(a: int): int {.async.} =
  await sleep(a)
  var b = a + 1
  return b

proc bar() {.async.} =
  let a = await foo(5)
  let b = await foo(6)
  echo a + b

waitFor bar()

If we pretend that sleep doesn't allocate, the whole waitFor operation above will not do a single allocation. The optimization happens in async functions on await calls.

TODO: Describe how it works in details

TODO:

  • Recursive calls
  • Generics
  • Cancellation
  • Nice stack traces

yasync's People

Contributors

yglukhov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.