Coder Social home page Coder Social logo

asynchronous's Introduction

Build Status

asynchronous

This library provides infrastructure for writing concurrent code using coroutines, multiplexing I/O access over sockets and other resources, running network clients and servers, and other related primitives.

It implements most of the python 3 asyncio API.

API Reference

Can be found at: http://dcarp.github.io/asynchronous/index.html

Implementation status

  • Timers (done)
  • Futures, Tasks (done)
  • Sockets (done)
  • Streams (done)
  • Subprocesses (not implemented)
  • Locks and semaphores (done)
  • Queues (done)

Why yet another async library? What is wrong with vibe.d?

  • asynchronous is a library and not a framework
  • it is not web-oriented, compatible with std.socket
  • arguably nicer API
  • event loop start/stop control
  • uses @Coroutine UDA to mark functions that could trigger a task (fiber) switch, although this is not enforced yet by the compiler.

Examples and tutorials

Some small examples can be found in the test directory or as unittests. For larger examples please use the Python/asyncio resources.

Please keep in mind that, in contrast with Python/asyncio, in D a coroutine MUST be called from within a Task, otherwise it causes a run-time error on the fiber switch. Basic rule: if not called from another coroutine, any coroutine call need to be wrapped by ensureFuture or EventLoop.createTask.

asynchronous's People

Contributors

belka-ew avatar dcarp avatar kubo39 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asynchronous's Issues

Partial writes not handled?

Prelude

From the posix standard regarding send and write it follows, that should a call from libasync to send be interrupted after it has already written some bytes it - and subsequently libasync's send wrapper functions for sockets - will return the number of bytes succesfully written (i.e. moved into the operating system send buffer) before the interrupt occurred.
Furthermore, EAGAIN or EWOULDBLOCK are only set by a call to send if the write would block, not if it was interrupted, so libasync will (correctly) not create a WRITE event later. See here, here, and here.

The issue

From what I can see here and here asynchronous - to the best of my understanding - seems to expect libasync to create a WRITE event when a send was not able to move all the requested bytes into the OS send buffer (as shown above, it will not).

Fortunately asynchronous buffers the data correctly, but as it stands, if it gets interrupted after sending some bytes, the rest of the data will not get sent until the next time someone actively tries to send data (resulting in a potentially significant - and theoretically unbounded - delay).
AFAIK loops akin to the following in both write and onWrite are necessary to ensure interruption of the send system call will not have such a detrimental effect.

if (this.writeBuffer.empty) {
    uint sent = void;
    do {
        sent = connection.send(cast(ubyte[]) data);
        data = data[sent .. $];
    } while (sent > 0 && !data.empty);
    if (sent == 0) writeBuffer = data.dup;
}
if (!writeBuffer.empty) {
    uint sent = void;
    do {
        sent = connection.send(cast(ubyte[]) writeBuffer);
        writeBuffer = writeBuffer[sent .. $];
    } while (sent > 0 && !writeBuffer.empty);
}

libfaketime support

without asyncio we could use the condition.wait(duration)-busyloop. with asyncio we could not override loop.call_at(timestamp).
There should be at least a guide for using asyncio together with faketime.
Currently just achieve this with a special injected task when using faketime.

Unix sockets not working

The README suggests that sockets have been fully implemented. When I try to use Unix sockets via openUnixConnection, however, it will crash either here (release mode) or here (debug mode).
I know that libasync has no official support for Unix socket yet, but I assumed that you were hijacking libasync' tcp functionality for unix sockets?

Warning for package asynchronous, configuration unittest

Hello,

every time I build asynchronous with dub 0.9.24 (dmd 0.68.2 and dmd 0.71.0) I get the following warning:

## Warning for package asynchronous, configuration unittest ##

The following compiler flags have been specified in the package description
file. They are handled by DUB and direct use in packages is discouraged.
Alternatively, you can set the DFLAGS environment variable to pass custom flags
to the compiler, or use one of the suggestions below:

unittests: Call DUB with --build=unittest

External event loop?

Hi there!

As a big fan of "asyncio" from Python I would like to use "asynchronous" in one of my pet projects. However I'm having some problems integrating an external event loop in place of built-in "libasync". One of them AFAIU is rather minor but annoying - EventLoop.startServing from events.d has an argument of type ServerImpl which has "package" visibility and hence implementing EventLoop subclass outside of the package is impossible without hacks. Currently I've solved the issue by making ServerImpl "public" but it definitely doesn't feel right. Is there a better way to solve this?

Thanks in advance!

more about project

Can you maybe give more infos about the project in the Readme (or at least here)?
What are the main purposes of the library?
Is it only for easy porting of python code or is it a general library for async programming?
Is it comparable with vibe:core? What is different from other libraries?
And maybe some general words for not python people..
The thing is I'm looking for a library that creates a layer over libasync with basic async functions and data structures to build on it. And there isn't much I could find.
Thanks

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.