Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 59 lines (43 sloc) 2.045 kb
5a3fb2d @rvirding Added Tim Dysinger's ping_pong.lfe as an example.
authored
1 ;; Copyright (c) Tim Dysinger tim <[<-on->]> dysinger.net
2
3 ;; Permission is hereby granted, free of charge, to any person obtaining a copy
4 ;; of this software and associated documentation files (the "Software"), to deal
5 ;; in the Software without restriction, including without limitation the rights
6 ;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 ;; copies of the Software, and to permit persons to whom the Software is
8 ;; furnished to do so, subject to the following conditions:
9
10 ;; The above copyright notice and this permission notice shall be included in
11 ;; all copies or substantial portions of the Software.
12
13 ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 ;; THE SOFTWARE.
20
21 (defmodule ping_pong
13566f1 @rvirding Restructure ping_pong.lfe to better show callbacks/client API
authored
22 (export (start_link 0) (ping 0))
23 (export (init 1) (handle_call 3) (handle_cast 2)
5a3fb2d @rvirding Added Tim Dysinger's ping_pong.lfe as an example.
authored
24 (handle_info 2) (terminate 2) (code_change 3))
25 (behaviour gen_server)) ;Just indicates intent
26
13566f1 @rvirding Restructure ping_pong.lfe to better show callbacks/client API
authored
27 (defun start_link ()
28 (: gen_server start_link
29 (tuple 'local 'ping_pong) 'ping_pong (list) (list)))
30
31 ;; Client API
5a3fb2d @rvirding Added Tim Dysinger's ping_pong.lfe as an example.
authored
32
33 (defun ping ()
34 (: gen_server call 'ping_pong 'ping))
35
13566f1 @rvirding Restructure ping_pong.lfe to better show callbacks/client API
authored
36 ;; Gen_server callbacks
5a3fb2d @rvirding Added Tim Dysinger's ping_pong.lfe as an example.
authored
37
38 (defrecord state (pings 0))
39
40 (defun init (args)
41 (tuple 'ok (make-state pings 0)))
42
43 (defun handle_call (req from state)
44 (let* ((new-count (+ (state-pings state) 1))
45 (new-state (set-state-pings state new-count)))
46 (tuple 'reply (tuple 'pong new-count) new-state)))
47
48 (defun handle_cast (msg state)
49 (tuple 'noreply state))
50
51 (defun handle_info (info state)
52 (tuple 'noreply state))
53
54 (defun terminate (reason state)
55 'ok)
56
57 (defun code_change (old-vers state extra)
58 (tuple 'ok state))
Something went wrong with that request. Please try again.