diff --git a/.travis.yml b/.travis.yml index 21897a2..c3282fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js dist: trusty sudo: required -node_js: 6 +node_js: 9 install: - npm install -g bower - npm install diff --git a/bower.json b/bower.json index 7f5e81e..78cd836 100644 --- a/bower.json +++ b/bower.json @@ -15,11 +15,11 @@ "package.json" ], "dependencies": { - "purescript-aff": "^4.0.2", - "purescript-refs": "^3.0.0" + "purescript-aff": "^5.0.0", + "purescript-refs": "^4.1.0" }, "devDependencies": { - "purescript-test-unit": "^13.0.0", - "purescript-parallel": "^3.3.1" + "purescript-test-unit": "^14.0.0", + "purescript-parallel": "^4.0.0" } } diff --git a/package.json b/package.json index 1d57209..0399d39 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "test": "pulp test" }, "devDependencies": { - "pulp": "^12.0.1", - "purescript": "^0.11.7", + "pulp": "^12.3.0", + "purescript": "^0.12.0", "purescript-psa": "^0.6.0", "rimraf": "^2.6.2" } diff --git a/src/Control/Monad/Aff/Reattempt.purs b/src/Effect/Aff/Reattempt.purs similarity index 68% rename from src/Control/Monad/Aff/Reattempt.purs rename to src/Effect/Aff/Reattempt.purs index 18c1de4..37e3784 100644 --- a/src/Control/Monad/Aff/Reattempt.purs +++ b/src/Effect/Aff/Reattempt.purs @@ -1,10 +1,10 @@ -module Control.Monad.Aff.Reattempt where +module Effect.Aff.Reattempt where import Prelude -import Control.Monad.Aff (Aff, delay, forkAff, supervise) -import Control.Monad.Eff.Class (liftEff) -import Control.Monad.Eff.Ref (newRef, readRef, writeRef, REF) +import Effect.Aff (Aff, delay, forkAff, supervise) +import Effect.Class (liftEffect) +import Effect.Ref (new, read, write) import Control.Monad.Error.Class (catchError, throwError) import Data.Time.Duration (Milliseconds) @@ -18,14 +18,14 @@ import Data.Time.Duration (Milliseconds) -- | When an attempt to run the provided `Aff` succeeds the `Aff` returned by `reattempt` -- | will succeed. When no attempts succeed the `Aff` returned by `reattempt` will fail -- | with the `Error` raised by the last attempt. -reattempt ∷ ∀ e a. Milliseconds → Aff (ref ∷ REF | e) a → Aff (ref ∷ REF | e) a +reattempt ∷ ∀ a. Milliseconds → Aff a → Aff a reattempt ms aff = supervise do - elapsed ← liftEff $ newRef false + elapsed ← liftEffect $ new false _ ← forkAff do delay ms - liftEff $ writeRef elapsed true + liftEffect $ write true elapsed let attempt = aff `catchError` \error → do - shouldRethrow ← liftEff $ readRef elapsed + shouldRethrow ← liftEffect $ read elapsed if shouldRethrow then throwError error else attempt diff --git a/test/Main.purs b/test/Main.purs index abef010..695b4cf 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,14 +1,8 @@ module Test.Main where import Prelude - +import Effect.Aff import Control.Alt ((<|>)) -import Control.Monad.Aff (Aff, attempt, delay) -import Control.Monad.Aff.AVar (makeVar, takeVar, putVar, AVar, AVAR) -import Control.Monad.Aff.Reattempt (reattempt) -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE) -import Control.Monad.Eff.Ref (REF) import Control.Parallel.Class (parallel, sequential) import Control.Plus (empty) import Data.Array (head, tail) @@ -18,12 +12,15 @@ import Data.Maybe (maybe, fromMaybe) import Data.Newtype (unwrap) import Data.Time.Duration (Milliseconds(..)) import Data.Unfoldable (replicate) +import Effect (Effect) +import Effect.Aff.AVar (new, take, put, AVar) +import Effect.Aff.Reattempt (reattempt) +import Effect.Console (log) import Test.Unit (test, suite) import Test.Unit.Assert (assert) -import Test.Unit.Console (TESTOUTPUT) import Test.Unit.Main (runTest) -failAffsForDurationAndNumberOfAttempts ∷ ∀ e. Milliseconds → Int → Array (Aff e Unit) +failAffsForDurationAndNumberOfAttempts ∷ Milliseconds → Int → Array (Aff Unit) failAffsForDurationAndNumberOfAttempts timeout attemptCount = seq where seq = replicate attemptCount do @@ -31,13 +28,13 @@ failAffsForDurationAndNumberOfAttempts timeout attemptCount = seq empty interval = Milliseconds (unwrap timeout / toNumber attemptCount) -affDouble ∷ ∀ e. AVar (Array (Aff (avar ∷ AVAR | e) Unit)) → Aff (avar ∷ AVAR | e) Unit +affDouble ∷ AVar (Array (Aff Unit)) -> Aff Unit affDouble affsVar = do - affs ← takeVar affsVar - putVar (fromMaybe [] (tail affs)) affsVar - maybe (pure unit) id $ head affs + affs ← take affsVar + put (fromMaybe [] (tail affs)) affsVar + maybe (pure unit) identity $ head affs -main ∷ ∀ eff. Eff (console ∷ CONSOLE, testOutput ∷ TESTOUTPUT, ref ∷ REF, avar ∷ AVAR | eff) Unit +main ∷ Effect Unit main = runTest do test "When the Aff never succeeds the returned Aff should fail" do result ← attempt $ reattempt (Milliseconds 100.0) do @@ -46,7 +43,7 @@ main = runTest do assert "The returned Aff did not fail" $ Either.isLeft result test "When the timeout will elapse before any attempts to run the Aff are successful the returned Aff should fail" do - seq ← makeVar $ failAffsForDurationAndNumberOfAttempts (Milliseconds 1000.0) 10 + seq ← new $ failAffsForDurationAndNumberOfAttempts (Milliseconds 1000.0) 10 result ← attempt $ reattempt (Milliseconds 100.0) (affDouble seq) assert "The returned Aff did not fail" $ Either.isLeft result @@ -59,12 +56,12 @@ main = runTest do suite "When the Aff will succeed during an attempt started before the timeout will elapse" do test "The returned Aff should be successful" do - seq ← makeVar $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 + seq ← new $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 result ← attempt $ reattempt (Milliseconds 100000000.0) (affDouble seq) assert "The returned Aff failed" $ Either.isRight result test "The returned Aff should not wait for the timeout to elapse in order to succeed" do - seq ← makeVar $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 + seq ← new $ failAffsForDurationAndNumberOfAttempts (Milliseconds 100.0) 10 let parReattempt = parallel (reattempt (Milliseconds 100000000.0) (affDouble seq) $> true) parLater = parallel do