Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoduncan committed Apr 27, 2012
0 parents commit b756662
Show file tree
Hide file tree
Showing 5 changed files with 973 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
/target
/lib
/classes
/checkouts
pom.xml
*.jar
*.class
.lein-deps-sum
.lein-failures
.lein-plugins
67 changes: 67 additions & 0 deletions README.md
@@ -0,0 +1,67 @@
# pallet-fsmop

A finite state machine composition library.

The library is built on composing FSM's with well defined initial and final
states. The FSM's are built using [Pallet-fsm][pallet-fsm], a library
for constructing arbitrary finite state machines.

The fsm's that can be composed should have an :init initial state, and should
respond to the :start event. They should have :completed, :failed, :aborted,
and maybe :timed-out as terminal states.

## Usage

FSM's are built as functions, and then executed using the `operate` function,
which returns a data-structure. The return data-structure can be deref'd to
block until completion.

The library comes with a comprehension `dofsm` for building FSMs. In this first
example, we use the `result` fsm, which takes a non-fsm value and creates a fsm
that returns it.

```clj
(let [op (fn [v] (dofsm result
[x (result 1)
x (result (+ x 2))]
x))
op (operate (op :ok))]
@op ; => 3
(complete? op) ; => true
(failed? op) ; => nil
```

Other built-in fsms are `delay-for`, `success` and `fail`.

The library also provides higher order fsm's. The `timeout` form adds a timeout
to another fsm.

```clj
(let [op (fn [delay-length]
(dofsm delay-op
[_ (timeout
(delay-for delay-length :ms)
500 :ms)]
_))
op (operate (op 500))]
@op)
```

The code above will time-out, if passed a delay-length greater than 500ms.

Another higher order fsm is `map*`, that will run a sequence of fsm's in
parallel and wait for them to all complete.

## Installation

To use pallet-fsmop, add the following to your :dependencies:

[pallet-fsm-op "0.1.0-SNAPSHOT"]

## License

Copyright © 2012 Hugo Duncan

Distributed under the Eclipse Public License.

[pallet-fsm]: https://github.com/pallet/pallet-fsm "Pallet-fsm library"
10 changes: 10 additions & 0 deletions project.clj
@@ -0,0 +1,10 @@
(defproject pallet-fsmop "0.1.0-SNAPSHOT"
:description "FSM composition"
:url "https://github.com/palletops/pallet-fsmop"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/tools.logging "0.2.3"]
[pallet-fsm "0.1.0-SNAPSHOT"]
[pallet-map-merge "0.1.0-SNAPSHOT"]
[pallet-thread "0.1.0-SNAPSHOT"]])

0 comments on commit b756662

Please sign in to comment.