Skip to content

Commit

Permalink
first demo, broken
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpmayer committed Apr 27, 2015
1 parent ae8d6a1 commit abe2cbd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
elm-stuff
elm-stuff
elm.js
1 change: 1 addition & 0 deletions elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"exposed-modules": [
"Concurrent"
],
"native-modules": true,
"dependencies": {
"elm-lang/core": "2.0.0 <= v < 3.0.0",
"imeckler/queue": "1.0.0 <= v < 2.0.0"
Expand Down
4 changes: 3 additions & 1 deletion src/Concurrent.elm
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ https://hackage.haskell.org/package/base/docs/Control-Concurrent-MVar.html
-}

import Task exposing (Task, andThen, succeed)
import Native.Concurrent
import Queue

type MVar a = OpaqueMVar

newEmptyMVar : Task x (MVar a)
newEmptyMVar = Native.Concurrent.newEmptyMVar
newEmptyMVar = Native.Concurrent.newEmptyMVar ()

newMVar : a -> Task x (MVar a)
newMVar value =
Expand Down
21 changes: 21 additions & 0 deletions src/Examples/Handoff.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

module Handoff where

import Concurrent exposing (MVar, newEmptyMVar, takeMVar, putMVar)
import Graphics.Element exposing (show)
import Task exposing (Task, andThen, succeed, spawn)

main = show "Test"

producer : MVar Int -> Task x ()
producer sync = putMVar sync 5

consumer : MVar Int -> Task x ()
consumer sync = succeed ()

port startup : Task x ()
port startup =
newEmptyMVar `andThen` \sync ->
spawn (producer sync) `andThen` \_ ->
spawn (consumer sync) `andThen` \_ ->
succeed ()
11 changes: 8 additions & 3 deletions src/Native/Concurrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Elm.Native.Concurrent.make = function(localRuntime) {
var Queue = Elm.Queue.make(localRuntime);
var Task = Elm.Native.Task.make(localRuntime);

function newEmptyMVar()
function newEmptyMVar(_fake)
{
return {
return Task.succeed({
value: Maybe.Nothing,
consumer: {
flag: {},
Expand All @@ -24,7 +24,7 @@ Elm.Native.Concurrent.make = function(localRuntime) {
flag: {},
queue: Queue.empty
}
};
});
}

function _tryWakeup(mvar, name) {
Expand Down Expand Up @@ -97,4 +97,9 @@ Elm.Native.Concurrent.make = function(localRuntime) {
});
}

return localRuntime.Native.Concurrent.values = {
newEmptyMVar: newEmptyMVar,
takeMVar: takeMVar,
putMVar: F2(putMVar)
};
}

0 comments on commit abe2cbd

Please sign in to comment.