GithubHelp home page GithubHelp logo

at-at's Introduction

                                        ________
                                    _,.-Y  |  |  Y-._
                                .-~"   ||  |  |  |   "-.
                                I" ""=="|" !""! "|"[]""|     _____
                                L__  [] |..------|:   _[----I" .-{"-.
                               I___|  ..| l______|l_ [__L]_[I_/r(=}=-P
                              [L______L_[________]______j~  '-=c_]/=-^
                               \_I_j.--.\==I|I==_/.--L_]
                                 [_((==)[`-----"](==)j
                                    I--I"~~"""~~"I--I
                                    |[]|         |[]|
                                    l__j         l__j
                                    |!!|         |!!|
                                    |..|         |..|
                                    ([])         ([])
                                    ]--[         ]--[
                                    [_L]         [_L]  -Row
                                   /|..|\       /|..|\
                                  `=}--{='     `=}--{='
                                 .-^--r-^-.   .-^--r-^-.
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                      __               __
                               ____ _/ /_       ____ _/ /_
                              / __ `/ __/______/ __ `/ __/
                             / /_/ / /_ /_____/ /_/ / /_
                             \__,_/\__/       \__,_/\__/

at-at

Simple ahead-of-time function scheduler. Allows you to schedule the execution of an anonymous function for a point in the future.

Basic Usage

First pull in the lib:

(use 'at-at)

Next, schedule the function of your dreams. Here we schedule the function to execute in 1000 ms from now (i.e. 1 second):

(at (+ 1000 (now)) #(println "hello from the past!"))

You can also schedule functions to occur periodically. Here we schedule the function to execute every second:

(every 1000 #(println "I am cool!"))

This can easily be stopped with cancel or its synonym stop:

(stop *1)

Finally, it's also possible to start a periodic repeating fn with an inital delay:

(every 1000 #(println "I am cool!") 2000)

Pools

at-at uses ScheduledThreadPoolExecutors behind the scenes which use a thread pool to run the scheduled tasks. There is a default pool which is created for you with (+ cpu-count 2) threads. However, you may create your own and run them separately.

For example, here we create a pool with 5 threads:

(def my-pool (mk-pool 5))

We can then use this pool to run our own periodic

(every 1000 #(println "I am super cool!") my-pool)

And then throw in our old friend running on the default pool:

(every 1000 #(println "I used to be cool until you made your own pool!"))

When necessary it's possible to stop and reset a given pool:

(stop-and-reset-pool! my-pool)

We can also stop and reset the default pool:

(stop-and-reset-pool!)

Install

Fetch at-at from github: https://github.com/overtone/at-at or pull from clojars: [overtone/at-at "0.0.1"]

History

at-at was extracted from the awesome music making wonder that is Overtone (http://github.com/overtone/overtone)

Authors

  • Sam Aaron
  • Jeff Rose

(Ascii art borrowed from http://www.sanitarium.net/jokes/getjoke.cgi?132)

at-at's People

Contributors

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