Coder Social home page Coder Social logo

periodically's Introduction

Periodically

A minimal erlang library which allows for periodically calling a function. Built on top of gen_server so it's integratable with supervisor the same as any other gen_server

Usage

The library comes with a Makefile, but it's just a single erl file so you can integrate it however you like. I prefer sticking it in deps/ and running erl with -pa deps/*/ebin/ but it's up to you.

As far as using it in code, there's two methods, periodically:start and periodically:start_link. The difference between them is analogous to gen_server. They take three arguments, a gen_server name (passed straight in as the first argument to gen_server:start(_link)/4), a period in milliseconds, and a function. The function can either be an anonymous function or in the form {Module,Method,Args}.

Example

%Starts a gen_server named thing1, runs the anonymous function every 3 seconds
periodically:start({local,thing1},3000,fun() -> io:fwrite("thing1 says hi!\n") end),

%Starts a gen_server named thing2 (and links it), runs ?MODULE:thing2_test([]) every
%2 seconds
periodically:start_link({local,thing2},2000,{?MODULE,thing2_test,[]}).

periodically's People

Watchers

miebach avatar James Cloos 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.