Skip to content

Compiler/0.12 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ language: node_js
dist: trusty
sudo: required
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
- npm install -g bower
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
- bower install --production
Expand Down
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"package.json"
],
"dependencies": {
"purescript-eff": "^3.0.0"
"purescript-effect": "^2.0.0"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
"purescript-refs": "^3.0.0",
"purescript-console": "^3.0.0"
"purescript-assert": "^4.0.0",
"purescript-refs": "^4.0.0",
"purescript-console": "^4.1.0"
}
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"test": "pulp test"
},
"devDependencies": {
"eslint": "^3.19.0",
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"rimraf": "^2.6.1"
"eslint": "^4.19.1",
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
File renamed without changes.
32 changes: 7 additions & 25 deletions src/Control/Monad/Eff/Timer.purs → src/Effect/Timer.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Control.Monad.Eff.Timer
( TIMER
, TimeoutId
module Effect.Timer
( TimeoutId
, setTimeout
, clearTimeout
, IntervalId
Expand All @@ -10,10 +9,7 @@ module Control.Monad.Eff.Timer

import Prelude

import Control.Monad.Eff (kind Effect, Eff)

-- | The effect for the usage of a JavaScript timer.
foreign import data TIMER :: Effect
import Effect (Effect)

-- | The ID of a timer started with `setTimeout`.
newtype TimeoutId = TimeoutId Int
Expand All @@ -26,18 +22,11 @@ derive instance ordTimeoutId :: Ord TimeoutId
-- |
-- | The timeout delay value is capped at 4ms by the JS API, any value less than
-- | this will be clamped.
foreign import setTimeout
:: forall eff
. Int
-> Eff (timer :: TIMER | eff) Unit
-> Eff (timer :: TIMER | eff) TimeoutId
foreign import setTimeout :: Int -> Effect Unit -> Effect TimeoutId

-- | Cancels a timeout. If the timeout has already been cancelled or has already
-- | elapsed this will have no effect.
foreign import clearTimeout
:: forall eff
. TimeoutId
-> Eff (timer :: TIMER | eff) Unit
foreign import clearTimeout :: TimeoutId -> Effect Unit

-- | The ID of a timer started with `setInterval`.
newtype IntervalId = IntervalId Int
Expand All @@ -51,15 +40,8 @@ derive instance ordIntervalId :: Ord IntervalId
-- |
-- | The interval delay value is capped at 4ms by the JS API, any value less
-- | than this will be clamped.
foreign import setInterval
:: forall eff
. Int
-> Eff (timer :: TIMER | eff) Unit
-> Eff (timer :: TIMER | eff) IntervalId
foreign import setInterval :: Int -> Effect Unit -> Effect IntervalId

-- | Cancels an interval timer. If the interval has already been cancelled this
-- | will have no effect.
foreign import clearInterval
:: forall eff
. IntervalId
-> Eff (timer :: TIMER | eff) Unit
foreign import clearInterval :: IntervalId -> Effect Unit
29 changes: 14 additions & 15 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,50 @@ module Test.Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console as C
import Control.Monad.Eff.Ref as R
import Control.Monad.Eff.Timer as T
import Effect (Effect)
import Effect.Console as C
import Effect.Ref as R
import Effect.Timer as T
import Test.Assert (assert)

import Test.Assert (ASSERT, assert)

main :: Eff (ref :: R.REF, timer :: T.TIMER, console :: C.CONSOLE, assert :: ASSERT) Unit
main :: Effect Unit
main = do
counter <- R.newRef 0
counter <- R.new 0

void $ T.setTimeout 10 do
C.log "timeout increment counter"
R.modifyRef counter (_ + 1)
void $ R.modify (_ + 1) counter

void $ T.setTimeout 50 do
C.log "timeout check counter"
n <- R.readRef counter
n <- R.read counter
assert $ n == 1

void $ T.setTimeout 100 do

t <- T.setTimeout 20 do
R.modifyRef counter (_ + 1)
void $ R.modify (_ + 1) counter

T.clearTimeout t

void $ T.setTimeout 50 do
C.log "check timeout never ran"
n <- R.readRef counter
n <- R.read counter
assert $ n == 1

void $ T.setTimeout 200 do

i <- T.setInterval 20 do
C.log "interval increment counter"
R.modifyRef counter (_ + 1)
void $ R.modify (_ + 1) counter

void $ T.setTimeout 90 do
T.clearInterval i
C.log "interval check counter"
n <- R.readRef counter
n <- R.read counter
assert $ n == 5

void $ T.setTimeout 150 do
C.log "check interval has stopped"
n <- R.readRef counter
n <- R.read counter
assert $ n == 5