{"id":21991925,"url":"https://github.com/elct9620/tide.ex","last_synced_at":"2025-07-03T16:32:11.470Z","repository":{"id":62430425,"uuid":"245672761","full_name":"elct9620/tide.ex","owner":"elct9620","description":"Communicate with Ruby via Erlport","archived":false,"fork":false,"pushed_at":"2020-03-26T13:16:01.000Z","size":60,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T09:15:56.657Z","etag":null,"topics":["elixir","ruby"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elct9620.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-07T17:06:45.000Z","updated_at":"2021-07-03T22:13:17.000Z","dependencies_parsed_at":"2022-11-01T20:18:56.748Z","dependency_job_id":null,"html_url":"https://github.com/elct9620/tide.ex","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/elct9620/tide.ex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elct9620%2Ftide.ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elct9620%2Ftide.ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elct9620%2Ftide.ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elct9620%2Ftide.ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elct9620","download_url":"https://codeload.github.com/elct9620/tide.ex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elct9620%2Ftide.ex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263360790,"owners_count":23454784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","ruby"],"created_at":"2024-11-29T20:12:11.159Z","updated_at":"2025-07-03T16:32:11.447Z","avatar_url":"https://github.com/elct9620.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"Tide [![Hex.pm](https://img.shields.io/hexpm/v/tide)](https://hex.pm/packages/tide) [![Build Status](https://travis-ci.com/elct9620/tide.ex.svg?branch=master)](https://travis-ci.com/elct9620/tide.ex)\n===\n\nSimilar to [elixir/export](https://github.com/fazibear/export) but design for asynchronous.\n\n## Installation\n\nAdding `tide` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:tide, \"~\u003e 0.2.1\"}\n  ]\nend\n```\n\n## Usage\n\nStart `Tide.Supervisor` to create Ruby worker pool\n\n```ex\nchildren = [\n  {Tide.Supervisor, root: :code.priv_dir(:app_name) |\u003e Path.join(\"ruby\"), file: \"app\"},\n  # ...\n]\noptions = [strategy: :one_for_one, name: __MODULE__]\n\nSupervisor.start_link(children, options)\n```\n\n### Register Event\n\nCreate a Ruby script (e.g. `priv/ruby/app.rb`) and put your code\n\n```ruby\n# Immediately will use the return value\nElixir::Tide.on(\"say\") do |name|\n  reply :ok, \"Hello #{name}\"\nend\n\n# Async event use \"Tide.Agent.emit\"\nElixir::Tide.on(\"sleep\") do |wait_time|\n  sleep wait_time.to_i\n  reply :ok, \"I am awake!\"\nend\n```\n\n### Agent\n\nStart a `Tide.Agent` to manage events\n\n```ex\n{:ok, pid} = Tide.Agent.start_link()\n```\n\nExecute event (return immediately)\n\n```ex\n{:ok, message } = Tide.Agent.exec(pid, \"say\", [\"World\"])\n# =\u003e \"Hello World\"\n```\n\nEmit event (asynchronous, and managed by `Tide.Reaction`)\n\n```ex\n{:ok, message } = Tide.Agent.emit(pid, \"sleep\", [1])\n# After 1 seconds\n{:ok, message } =\n  Tide.Agent.reaction(pid)\n  |\u003e Tide.Reaction.next\n\n# =\u003e \"I am awake!\"\n```\n\n### Reaction\n\nThe `Tide.Reaction` is a queue collect the reply from Ruby. You can use it to prevent the `Tide.Agent.exec` blocking your process.\n\n### State\n\nThe Erlport didn't support call Erlang function from Thread, and to ensure your Ruby script can recover from crash.\nUse the `Tide.State` to persist the state and it will pass to Ruby by Tide.\n\nAttach a state to agent\n\n```ex\n{:ok, state} = Tide.State.start_link()\n{:ok, agent} = Tide.Agent.start_link(state)\n```\n\nWhen we execute an event the state will convert to keyword list and save as `Tide::State` object.\nThat means the `Map` or `Keyword List` is accept as a state.\n\n```ex\nstate = %{user_id: 1, name: \"John\"}\n{:ok, agent} = Tide.Agent.start_link(state)\n```\n\nThe state is part of agent and unable directly change it, but we can use `Tide.Agent.update/2` to update it.\n\n```ex\nagent\n|\u003e Tide.Agent.update(fn(state) -\u003e state |\u003e Map.put(:name, \"Bob\")  end)\n```\n\nOr replace state to another new state\n\n```ex\nagent\n|\u003e Tide.Agent.update(%{user_id: 1, name: \"Alice\"})\n```\n\n## Roadmap\n\n* [x] Worker Pool\n  * [x] Customize root directory by `root` options\n  * [x] Customize main file by `file` options\n  * [x] Customize initialize function by `function` options\n  * [ ] Customize environment variable by `env` options\n* [ ] User Defined Module\n  * [ ] Customize `Tide.Reaction`\n  * [ ] Customize `Tide.State`\n  * [x] Customize `Tide.Supervisor`\n  * [ ] Customize `Tide.Agent`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felct9620%2Ftide.ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felct9620%2Ftide.ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felct9620%2Ftide.ex/lists"}