Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adamkittelson/block_timer
Macros to use :timer.apply_after and :timer.apply_interval with a block
https://github.com/adamkittelson/block_timer
Last synced: about 1 month ago
JSON representation
Macros to use :timer.apply_after and :timer.apply_interval with a block
- Host: GitHub
- URL: https://github.com/adamkittelson/block_timer
- Owner: adamkittelson
- Created: 2014-07-27T18:42:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-01T17:23:05.000Z (about 10 years ago)
- Last Synced: 2024-10-05T08:15:39.313Z (2 months ago)
- Language: Elixir
- Homepage:
- Size: 191 KB
- Stars: 10
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Macros to use :timer.apply_after and :timer.apply_interval with a block. (Date and Time)
- fucking-awesome-elixir - block_timer - Macros to use :timer.apply_after and :timer.apply_interval with a block. (Date and Time)
- awesome-elixir - block_timer - Macros to use :timer.apply_after and :timer.apply_interval with a block. (Date and Time)
README
[![Build Status](https://travis-ci.org/adamkittelson/block_timer.svg?branch=master)](https://travis-ci.org/adamkittelson/block_timer)
BlockTimer
=====Macros to use :timer.apply_after and :timer.apply_interval with a block, e.g.:
```elixir
iex(1)> import BlockTimer
nil
iex(2)> apply_after 3 |> seconds, do: IO.puts "hello"
{:ok, {1407446427626194, #Reference<0.0.0.371>}}
iex(3)> hello
``````elixir
iex(1)> import BlockTimer
nil
iex(2)> {:ok, counter} = Agent.start_link fn -> 0 end
{:ok, #PID<0.70.0>}
iex(3)> {:ok, tref} = apply_interval 1 |> seconds do
...(3)> Agent.update(counter, fn(count) -> count + 1 end)
...(3)> IO.puts Agent.get(counter, fn(count) -> count end)
...(3)> end
{:ok, {:interval, #Reference<0.0.0.382>}}
iex(4)> 1
2
3
4
5
:timer.cancel tref
{:ok, :cancel}
iex(5)>
```