Skip to content

Commit 100029c

Browse files
committed
make aff newtype so it's easier to define ffi, begin working on test suite
1 parent 0afa65a commit 100029c

File tree

6 files changed

+535
-3
lines changed

6 files changed

+535
-3
lines changed

Gruntfile.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@ module.exports = function(grunt) {
22
"use strict";
33

44
grunt.initConfig({
5-
5+
psc: {
6+
options: {
7+
main: "Examples",
8+
modules: ["Examples"]
9+
},
10+
example: {
11+
src: ["<%=libFiles%>", "examples/Prelude.purs"],
12+
dest: "output/examples.js"
13+
}
14+
},
615
libFiles: [
716
"src/**/*.purs",
17+
"examples/**/*.purs",
818
"bower_components/purescript-*/src/**/*.purs",
919
],
1020

@@ -37,5 +47,6 @@ module.exports = function(grunt) {
3747
grunt.loadNpmTasks('grunt-jsvalidate');
3848

3949
grunt.registerTask("make", ["pscMake", "jsvalidate", "dotPsci", "pscDocs"]);
50+
grunt.registerTask("test", ["jsvalidate", "psc"]);
4051
grunt.registerTask("default", ["make"]);
4152
};

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ do resp <- (Ajax.get "http://foo.com") `catchError` (\e -> pure defaultResponse)
139139

140140
Thrown exceptions are propagated on the error channel, and can be recovered from using `attempt` or `catchError`.
141141

142+
## Forking
143+
144+
Using the `forkAff`, you can "fork" an asynchronous computation, which means that its activities will not
145+
block the current thread of execution:
146+
147+
```purescript
148+
forkAff myAff
149+
```
150+
151+
Because Javascript is single-threaded, forking does not actually cause the computation to be run in a separate thread, it merely means the subsequent chain of computations will be executed without first waiting for the forked computation to complete.
152+
142153
## Variables
143154

144155
The `Control.Monad.Aff.Var` module contains asynchronous variables. These can

examples/src/Examples.purs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
module Examples where
22
import Control.Monad.Aff
3+
import Control.Monad.Eff.Class(liftEff)
4+
import Debug.Trace
35

4-
-- TODO
6+
foreign import data Time :: !
7+
8+
foreign import timeout """
9+
function timeout(time) {
10+
return function(error) {
11+
return function(success) {
12+
return function() {
13+
setTimeout(function() {
14+
try {
15+
success({})();
16+
} catch (e) {
17+
error(e)();
18+
}
19+
}, time);
20+
}
21+
}
22+
}
23+
}
24+
""" :: forall e. Number -> Aff (time :: Time | e) Unit
25+
26+
test_sequencing 0 = liftEff $ trace "Done"
27+
test_sequencing n = do
28+
timeout 1000
29+
liftEff $ trace (show n ++ " seconds left")
30+
test_sequencing (n - 1)
31+
32+
main = launchAff $ do
33+
liftEff $ trace "Testing sequencing"
34+
test_sequencing 10

output/examples.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<script type="text/javascript" src="./examples.js"></script>
4+
</head>
5+
<body>
6+
<h1>Examples</h1>
7+
</body>
8+
</html>

0 commit comments

Comments
 (0)