This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
channelsDemo :: Process () | |
channelsDemo = do | |
(sp, rp) <- newChan :: Process (SendPort String, ReceivePort String) | |
-- send on a channel | |
spawnLocal $ sendChan sp "hello!" | |
-- receive on a channel | |
m <- receiveChan rp | |
say $ show m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sender(receiverPath: String) extends Actor { | |
val id = 1 | |
val ext = EventsourcingExtension(context.system) | |
val proxy = context.actorOf( | |
Props(new DestinationProxy(receiverPath))) | |
val channel = ext.channelOf(ReliableChannelProps(1, proxy) | |
.withRedeliveryMax(1000) | |
.withRedeliveryDelay(1 second) | |
.withConfirmationTimeout(2 seconds)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var i int | |
func makeCakeAndSend(cs chan string) { | |
i = i + 1 | |
cakeName := "Strawberry Cake " + strconv.Itoa(i) | |
fmt.Println("Making a cake and sending ...", cakeName) | |
cs <- cakeName //send a strawberry cake | |
} | |
func receiveCakeAndPack(cs chan string) { | |
s := <-cs //get whatever cake is on the channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.core.async | |
:as async | |
:refer [<! >! <!! timeout chan alt! go]]) | |
(defn fake-search [kind] | |
(fn [c query] | |
(go | |
(<! (timeout (rand-int 100))) | |
(>! c [kind query])))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search(Ch, Kind, Query) -> | |
timer:sleep(random:uniform(100) + 10), | |
enqueue(Ch, {Kind, Query}). | |
fake(Kind) -> | |
Ch = make(), | |
fun(Query) -> | |
spawn(?MODULE, search, [Ch, Kind, Query]), Ch | |
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() -> | |
Clients = ch:make(), | |
spawn(clients_generator, [Clients]), | |
lists:foreach(fun(_) -> | |
spawn(barber, [Clients]) | |
end, lists:seq(1,10)). | |
clients_generator(Clients) -> | |
ch:enqueue(client, Clients), | |
timer:sleep(random:uniform(100)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir ~/ElixirLang | |
$ cd ~/ElixirLang | |
$ brew install kerl | |
$ kerl build R16B01 r16b01 | |
$ kerl install r16b01 ~/erlang/r16b01 | |
$ . ~/erlang/r16b01/activate | |
$ erl | |
Erlang R16B01 (erts-5.10.2) [source] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] | |
Eshell V5.10.2 (abort with ^G) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Pipes | |
# defservice Profile do ... end | |
# defservice Device do ... end | |
# defservice Push do ... end | |
send = pipe do | |
profile <- Profile.all &1 | |
badge <- Profile.get_badge_size profile | |
device <- Device.sessions profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(1)> import Scala | |
nil | |
iex(2)> s = for do | |
...(2)> f <- [1,2,3] | |
...(2)> g <- [1,2,3] | |
...(2)> if (rem f+g, 2) == 0 | |
...(2)> yield {f, g*2} | |
...(2)> end | |
iex(3)> Enum.to_list s | |
[{1, 2}, {1, 6}, {2, 4}, {3, 2}, {3, 6}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Pairing a = Empty | Node a [Pairing a] | |
singleton :: Ord a => a -> Pairing a | |
singleton x = Node x [] | |
union :: Ord a => Pairing a -> Pairing a -> Pairing a | |
union Empty h2 = h2 | |
union h1 Empty = h1 | |
union t1@(Pairing h1 subs1) t2@(Pairing h2 subs) | |
| h1 < h2 = Pairing h1 t2:subs1 |