diff --git a/README.md b/README.md index 34e28b9..55e762c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,41 @@ # WaitForIt -**TODO: Add description** +Various ways to wait for things to happen. + +Since most Elixir systems are highly concurrent there must be a way to coordinate and synchronize +the concurrent processes in the system. While the language provides features such as +`Process.sleep/1` and `receive`/`after` that can be used implement such synhronization, they are +inconvenient to use for this purpose. WaitForIt builds on top of these language features to +provide convenient and easy-to-use facilities for synchronizing concurrent activities. While +this is likely most useful for test code in which tests must wait for concurrent or asynchronous +activities to complete, it is also useful in any scenario where concurrent processes must +coordinate their activity. Examples include asynchronous event handling, producer-consumer +processes, and time-based activity. + +There are three distinct forms of waiting provided: + + 1. The `wait` macro waits until a given expression evaluates to a truthy value. + 2. The `case_wait` macro waits until a given expression evaluates to a value that + matches any one of the given case clauses (looks like an Elixir `case` expression). + 3. The `cond_wait` macro waits until any one of the given expressions evaluates to a truthy + value (looks like an Elixir `cond` expression). + +See the [API reference](https://hexdocs.pm/wait_for_it/api-reference.html) for full documentation. + +## TODO + + * Use supervisor for condition variables. + * Support `:infinity` option for `:timeout` ## Installation -If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `wait_for_it` to your list of dependencies in `mix.exs`: +`wait_for_it` can be installed from Hex by adding `wait_for_it` to your list +of dependencies in `mix.exs`: ```elixir def deps do [ - {:wait_for_it, "~> 0.1.0"} + {:wait_for_it, "~> 1.0.0"} ] end ``` diff --git a/mix.exs b/mix.exs index d49b14a..cdd9639 100644 --- a/mix.exs +++ b/mix.exs @@ -4,9 +4,12 @@ defmodule WaitForIt.Mixfile do def project do [ app: :wait_for_it, - version: "0.1.0", + version: "1.0.0", + description: "Elixir library for waiting for things to happen", + source_url: "https://github.com/jvoegele/wait_for_it", elixir: "~> 1.5", start_permanent: Mix.env == :prod, + package: package(), deps: deps() ] end @@ -21,8 +24,17 @@ defmodule WaitForIt.Mixfile do # Run "mix help deps" to learn about dependencies. defp deps do [ - # {:dep_from_hexpm, "~> 0.3.0"}, - # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, + {:ex_doc, "~> 0.16.3"}, + ] + end + + defp package do + [ + name: :wait_for_it, + files: ["lib", "mix.exs", "README*", "LICENSE*"], + maintainers: ["Jason Voegele"], + licenses: ["Apache 2.0"], + links: %{"GitHub" => "https://github.com/jvoegele/wait_for_it"} ] end end diff --git a/mix.lock b/mix.lock new file mode 100644 index 0000000..e61531e --- /dev/null +++ b/mix.lock @@ -0,0 +1,2 @@ +%{"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}} diff --git a/test/wait_for_it_test.exs b/test/wait_for_it_test.exs index 9d915c9..9df1c30 100644 --- a/test/wait_for_it_test.exs +++ b/test/wait_for_it_test.exs @@ -1,7 +1,5 @@ defmodule WaitForItTest do use ExUnit.Case - doctest WaitForIt - import WaitForIt defp increment_counter do @@ -122,8 +120,8 @@ defmodule WaitForItTest do end test "accepts a :frequency option" do - :ok = cond_wait frequency: 1 do - 5 == increment_counter() -> :ok + 5 = cond_wait frequency: 1 do + (count = increment_counter; count > 4) -> count 2 + 2 == 5 -> 1984 :answer == 42 -> :question end