{"id":16019610,"url":"https://github.com/iboard/data_source","last_synced_at":"2025-04-10T01:06:19.224Z","repository":{"id":57488357,"uuid":"147114123","full_name":"iboard/data_source","owner":"iboard","description":"Elixir Datasource and DataStage","archived":false,"fork":false,"pushed_at":"2019-03-02T20:30:37.000Z","size":47,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T01:06:14.209Z","etag":null,"topics":["consumer","datasource","elixir","elixir-lang","hex"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/data_source","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iboard.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-02T19:10:55.000Z","updated_at":"2019-07-22T15:34:15.000Z","dependencies_parsed_at":"2022-08-29T13:31:51.357Z","dependency_job_id":null,"html_url":"https://github.com/iboard/data_source","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iboard%2Fdata_source","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iboard%2Fdata_source/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iboard%2Fdata_source/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iboard%2Fdata_source/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iboard","download_url":"https://codeload.github.com/iboard/data_source/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137888,"owners_count":21053775,"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":["consumer","datasource","elixir","elixir-lang","hex"],"created_at":"2024-10-08T17:04:55.969Z","updated_at":"2025-04-10T01:06:19.205Z","avatar_url":"https://github.com/iboard.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataSource\n[![Documentation](https://img.shields.io/badge/docs-hexpm-blue.svg)](http://hexdocs.pm/data_source/)\n[![Documentation](https://travis-ci.com/iboard/data_source.svg?branch=master)](https://travis-ci.com/iboard/data_source)\n\nPart of the `[PocketData][]` project. A DataSource is a \"Producer\" (of data)\nfor the system. It can be a simple counter, or a complex \"collector\", reading\nsensors from embedded systems or collecting data from foreign (web-)services.\n\n## Installation\n\nThe package is [available in Hex](https://hex.pm/packages/data_source), the package can be installed\nby adding `data_source` to your list of dependencies in `mix.exs`:\n\n      def deps do\n        [\n          {:data_source, \"~\u003e 0.1\"}\n        ]\n      end\n\n## Example\n\nThe best way to figure out how you can use this library is by having a look at \nthis [Test suite](https://github.com/iboard/hexpack-examples/blob/master/test/hexpack_examples_test.exs).\n\n\n\n      # Remember consumed events in state\n      defmodule ConsumerSpy do\n        use GenStage\n\n        def start_link(), do: GenStage.start_link(ConsumerSpy, [])\n        def init(state), do: {:consumer, state}\n\n        def handle_events(events, _from, state) do\n          # Simulate load\n          Process.sleep(10)\n          {:noreply, [], [events | state]}\n        end\n\n        def handle_call(:get, _from, state) do\n          {:reply, Enum.flat_map(state, \u0026 \u00261), [], state}\n        end\n      end\n\n      {:ok, datasource} = Datasource.start_link(0, fn state -\u003e {state, state + 1} end)\n      {:ok, producer} = Datasource.DataStage.start_link(datasource)\n      {:ok, consumer} = ConsumerSpy.start_link()\n\n      GenStage.sync_subscribe(consumer, to: producer, max_demand: 1)\n      Process.sleep(100)\n\n      ConsumerSpy.call(consumer, :get)\n      # =\u003e [0,1,2,3,...10]\n\nBecause the consumer delays for 10ms and we have 1 consumer only,\nin 100ms we can expect about 10 events. To process more than 10\nevents you can increase the number of consumers.\n\n## Datasources\n\nSome Datasources are defined in `lib/data_source`. Such as\n`Datasource.Counter`, `Datasource.File`, and more.\n\n\n[PocketData]: https://github.com/iboard/pocketdata\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiboard%2Fdata_source","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiboard%2Fdata_source","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiboard%2Fdata_source/lists"}