Giter Site home page Giter Site logo

soumith / async Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clementfarabet/async

0.0 3.0 0.0 692 KB

An async framework for Lua/Torch.

Lua 3.42% Shell 0.67% JavaScript 0.07% CSS 1.14% Ruby 0.03% C 92.71% Python 1.38% Objective-C 0.35% D 0.08% C++ 0.15%

async's Introduction

ASyNC

An async framework for Lua/Torch, based on LibUV (using Tim Caswell's luv library).

This lib is heavily inspired on the Node.js architecture. It's fun, elegant, and should be extremely efficient (a lot of testing is required).

The examples in tests/ should provide enough documentation on the API.

License

MIT License

Examples

Starting the event loop. At the end of any program, the event loop must be started. Nothing will be interpreted after this call, as it takes control of the runtime.

async.go()

It's useful to have a REPL (interpreter) running asynchronously, for debugging and live control of your programs:

async.repl()  -- fires up an asyncronous repl
async.repl.listen({host='0.0.0.0', port=8080})   -- fires up an async repl through a TCP server
async.repl.connect({host='0.0.0.0', port=8080})  -- connects to a remote repl through a TCP client

Common JS like timer controls:

async.setInterval(millis, function()
   print('printed every N millis')
end)
async.setTimeout(millis, function()
   print('printed once in N millis')
end)

CPU Info. Useful to know how many processors are available. This is a synchronous call.

print(async.cpuInfo())

A TCP server:

async.tcp.listen({host='0.0.0.0', port=8080}, function(client)
   -- Receive:
   client.ondata(function(chunk)
      -- Data:
      print('received: ' .. chunk)

      -- Reply:
      client.write('thanks!')
   end)

   -- Done:
   client.onend(function()
      print('client gone...')
   end)
end)

A TCP client:

async.tcp.connect({host='127.0.0.1', port=8080}, function(client)
   -- Write something
   client.write('something .. ' .. i)

   -- Callbacks
   client.ondata(function(chunk)
      print('received: ' .. chunk)
      client.close()
   end)

   -- Done:
   client.onend(function()
      print('connection closed...')
   end)
end)

File I/O. The low level interface is not complete yet, but the high-level one is final:

async.fs.readFile('LICENSE', function(content)
   print(content)
   async.fs.writeFile('LICENSE.copy', content, function(status, err)
      print('==> wrote file: ' .. (status or err))
   end)
end)

async's People

Contributors

clementfarabet avatar ocallaco avatar soumith avatar

Watchers

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