View Source shards_group (shards v1.1.1)

This module provides a dynamic supervisor for creating and/or deleting tables dynamically in runtime and as part of an existing supervision tree; any application supervision tree using shards.

Usage

To use shards and make the creates tables part of your application supervision tree, you have to add to your main supervisor:

   % Supervisor init callback
   init(GroupName) ->
     Children = [
       shards_group:child_spec(GroupName)
     ],
  
     {ok, {{one_for_one, 10, 10}, Children}}.

After your application starts, you can create and delete tables like so:

   > {ok, Pid, Tab} = shards_group:new_table(GroupName, mytab, [named_table]).
   {ok,<0.194.0>,#Ref<0.3052443831.2753691659.260835>}
  
   > shards_group:del_table(GroupName, mytab).
   ok

Summary

Functions

-spec child_spec(Name) -> ChildSpec
                    when Name :: atom() | undefined, ChildSpec :: supervisor:child_spec().
-spec del_table(SupRef, Tab) -> ok | {error, Reason}
                   when SupRef :: atom(), Tab :: shards:tab(), Reason :: not_found | simple_one_for_one.
Link to this function

new_table(SupRef, TabName, Options)

View Source
-spec new_table(SupRef, TabName, Options) -> {ok, TabPid, Tab} | {error, Reason}
                   when
                       SupRef :: atom() | pid(),
                       TabName :: atom(),
                       Options :: [shards:option()],
                       TabPid :: pid(),
                       Tab :: shards:tab(),
                       Reason :: term().

Equivalent to start_link(shards_group).

-spec start_link(Name) -> StartRet
                    when Name :: atom() | undefined, StartRet :: {ok, pid()} | {error, term()}.

Equivalent to stop(Pid, 5000).

-spec stop(SupRef, Timeout) -> ok when SupRef :: atom() | pid(), Timeout :: timeout().