GenServerなんかにある handle_info/2 の使い方をど忘れしてしまったので、メモ。 自身のブログを検索すると、 [Elixir in Action]OTP/GenServerを学んで非同期/並行処理を学ぶ にすでにメモってたのですが。 以下のような簡単なコールバックを実装し、スクリプトを実行してみます。 まずはGrnServerを持つプロセスを生成します。そのあと、 call や cast で定義されていないメッセージを send してあげると、ここでは handle_info/2 に拾われて処理を行います。 少し話がそれて、非同期通信の時に何らかの処理を終えた時に通知を受け取りたい場合、そういえば以下のように reply/2 を使って処理を非同期にプロセスに投げることできるのでしたね。上に貼ったリンク先を読み直してて思い出した… handle_infoも使うと、以下の通りにも書くことができる、と。 ここの、GenServerのドキュメントにも載っているやり方です。More
Category Archives: development
Design Document Template
A memo for me https://github.com/KazuCocoa/design-document-template This may help me when I try something stuff.More
[Elixir]Registerを覗く
key-value processとしてElixir1.4に入れる予定の Register というものが公開されました。 https://github.com/elixir-lang/registry 付属のベンチマークによると、以下のように高い性能が出ていることがわかります。 the result of https://github.com/elixir-lang/registry/blob/master/bench/ MacBook Pro (Retina, 15-inch, Late 2013) OS: Mac OS 10.11.6 processor: 2.6 GHz Intel Core i7 memory: 16 GB 1600 MHz DDR3 Erlang/OTP 18 $ TASKS=8 MIX_ENV=bench mix run bench/erlang.exs {835251, :ok} $ TASKS=8 MIX_ENV=bench mix run bench/gproc.exs {732408, :ok} $ TASKS=8 MIX_ENV=bench mix run…More
learning Rx
Reactiveを再度ざっと振り返るために、以下のlearnrxをやった。 http://reactivex.io/learnrx/ map や filter 、 reduce や take など、Elixirを学んだりしていると自然と学んだものだった。 Reactive、非同期通信とか扱いやすいけれどやっぱり使いすぎるとコールバックばかりでテストコードを書くことが大味になるし、使うのは適度が良さそう。More
[iOS]Run multi simulators with FBSimulatorControl
複数のシミュレータを1つの端末/OS上で起動可能な FBSimulatorControl はご存知の方も多いかもしれません。 それを使った時のメモ。最後の方に、XCTestを実行する時のものも。 installはリポジトリを参考に。 (以下は 0.2.0 のバージョン) listを表示 2つの端末を同時起動 help 以下のPR/議論で、結果の出力フォーマットとしてJUnitなんかを選択できるようになったようです。 formatterのサポート https://github.com/facebook/FBSimulatorControl/issues/281 https://github.com/facebook/FBSimulatorControl/pull/290 また、以下の通り .xctest を対象にすると、XCTestを実行可能なようです。 という形でテストを実行できる模様。 .xctest はAWS Device Farmとかでも使えるコレですね。 http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-ios-xctest.htmlMore
[Elixir]ets vs Agent
on-memory vs processであるets vs Agentに関して、過去に以下の議論があったのでメモ。 https://groups.google.com/forum/#!topic/elixir-lang-talk/RyhiBcD_Zvw 以下の回答は、Elixir in Actionを書かれたErlang developerの方 There are some gotchas with ETS: No garbage collection of individual rows. Memory is released when the owner process dies (and there’s no heir process). Data is copied to / from ETS table. Usually not a problem, but might be when individual rows are huge.…More
Download precompiled package and execute library with its binary
I’d like to run http_proxy without install package management for Elixir as portable aspect. So, I prepare simple shell script to help the problem. It is that downloading precompiled package and unzip it, run http_proxy with the precompiled mix. Example https://github.com/KazuCocoa/run_http_proxyMore
minimal ruby client for WebDriverAgent
WebDriverAgent developed by Facebook is one of WebDriver tool which run on iOS. Previous some posts, I investigated this module. And now, I develop minimal wrapper Ruby cli client to help some operations. https://github.com/KazuCocoa/wda_client I implemented some operations such as taking screenshots, getting source tree, status about the driver and install arbitrary app to the…More
[Elixir]read GenStage and try a bit
GenStageの0.3.0がリリースされたと合わせて、GenStageに関してのアナウンスがされたので触ってみました。合わせて、GenEventの問題点や解決したい問題がかかれているので参考になると思います。 http://elixir-lang.org/blog/2016/07/14/announcing-genstage/ GenStageとは https://github.com/elixir-lang/gen_stage#genstage に書いている通り、producerとconsumerの別れた役割を持つプロセスの間のイベントをやりとりするためのライブラリです。 GenEventだとイベントを1つの1つのプロセスで処理していたので、何かエラーが発生した時にsupervisorを再起動するというような戦略が取れないことだったりなど、データの流れを考える上で平行処理やその周辺に開発者が気を配らないといけない、と手間がかかっていました。そのため、開発者がデータの処理に集中できるように、そこら辺をいい感じにしてくれるものを用意するために作られたものがこれのようです。 3つの役割 GenStageは、0.3.0現在は3つの役割を持つことができます。 producer consumer producer_consumer 1は、callbackの実装時に handle_demand/2 を実装する必要があります。これは、2や3から要求が来た時に行う処理を書きます。2と3は handle_events/3 を実装する必要があります。これは、イベントを得た時に行う処理を書きます。 関係性の定義 GenStage.sync_subscribe c, to: b のように書くことで、このcとbの間にはconsumer(c)とproducer(b)の関係ができます。つまり、cからbに要求が送られ、それに対して行われた要求が処理されcに対して応答として帰ってきます。ここでは sync_subscribe/3 なので、同期的な挙動を行います。一定時間応答がなかったらtimeoutに成るし、そうなるまでcはbから返答を待ちます。 他にも async_subscribe/2 も存在して、これはこの関係が非同期的に行われる、ということですね。 https://hexdocs.pm/gen_stage/Experimental.GenStage.html#async_subscribe/2 https://hexdocs.pm/gen_stage/Experimental.GenStage.html#sync_subscribe/3 これらの関係性がわかるサンプル実装が以下にあります。 https://github.com/elixir-lang/gen_stage/blob/master/examples/producer_consumer.exs 最後に GenStageはまだ開発中で、 Experimental.GenStage.Flow の実装を控えているそうです。今はまだプロトタイプとしてのドキュメントが以下にあるだけですが、外部データの流れをうまく扱う Flow を練っているようですね。 https://hexdocs.pm/gen_stage/Experimental.GenStage.Flow.html ここら辺は以下のような使い方に寄与するみたいです。 Developers who maintain libraries that integrate with external data sources, be it a RabbitMQ, Redis or…More
[Android]Chat Client for Phoenix server
I implemented a chat server and an iOS application and posted about them on [Swift][Elixir]implement chat server and client. Today, I implemented easy an android chat application for the server. https://github.com/KazuCocoa/WebSocketDemoForAndroid Use Toothpick and Smoothie I use libraries called toothpick and smoothie as DI, such as Dagger but they are simpler than it. https://github.com/KazuCocoa/WebSocketDemoForAndroid/commit/24e9d3d8fa3abf8a8e1116b35334ff22d8d81d2e And…More