Giter Club home page Giter Club logo

aioli's Introduction

Aioli

Aioli (ayo-OH-lee) is a little sauce on top of Python's asyncio package. With a little aioli it makes it easier to take advantage of asyncio in synchronous code.

These helpers are intended for IO bound tasks that yield. If you're not yield'ing or if your code is CPU bound then aioli probably won't help you much unless you start getting fancy with passing in your own loops in with their own executors.

Await

The aioli.await() function calls a coroutine and blocks until it returns. With aioli.await() it's easier to call an asynchrounous coroutine from synchronous code.

@asyncio.coroutine
def func(x):
    yield from asyncio.sleep(random())
    return x

result = aioli.await(func(1))

Map

The aioli.map() functions applies the coroutine to every item of iterable. The results are yielded as they are available and in the same sort order as the iterable.

@asyncio.coroutine
def func(x):
    yield from asyncio.sleep(random())
    return x

for result in aioli.map(func, iterable):
    print(result)

Parallel

The aioli.parallel() function applies the coroutine to every item of an iterable. The difference with aioli.parallel() and aioli.map() is that the results are returned as they are available rather than in order.

@asyncio.coroutine
def inc(x):
    yield from asyncio.sleep(random())
    return x + 1

for result in aioli.parallel(func, iterable):
    print(result)

Filter

The aiolo.filter() function applies an asynchronous coroutine to an iterable and yields the results where the coroutine returns True. The results are yielded in same order as the iterable.

is_even = lambda x: x % 2 == 0
for result in aioli.map(is_even, range(0, 100)):
    print(result)

Filter false

The aioli.filterfalse() function is the same as aioli.filter() but returns those elements where the coroutine return False.

is_even = lambda x: x % 2 == 0
for result in aioli.map(is_even, range(0, 100)):
    print(result)

aioli's People

Stargazers

 avatar  avatar

Watchers

 avatar  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.