Git Product home page Git Product logo

couchdb-local's Introduction

local

hex.pm version Build Status Code Coverage License: MIT

A Local Name Registration Facility.

The library provides the following features:

  • Registration of locally scoped names
    • gen_server (and other OTP behaviours) can use the registration facility through {via, local, local:name()} formatted name
  • Can be embedded in another aplication

Documentation

QuickStart

# clone
$ git clone git://github.com/sile/local.git
$ cd local

# compile
$ make compile

# run tests
$ make eunit

# dialyze
$ make dialyze

# Erlang shell
$ make start
1> local:start(sample_name_server).
ok

Usage Example

%% Starts name server
> ok = local:start_name_server(sample_name_server).
> local:which_name_servers().
[sample_name_server]


%% Registers process name
> self().
<0.42.0>

> local:register_name({sample_name_server, hoge}, self()). % succeeded
yes

> local:register_name({sample_name_server, hoge}, self()). % failed: name collision
no

> local:whereis_name({sample_name_server, hoge}).
<0.42.0>

%% Registered name can be used as gen_server's via name
> gen_server:cast({via, local, {sample_name_server, hoge}}, hello).
ok

> flush().
Shell got {'$gen_cast',hello}
ok


%% Unregisters process name
> local:unregister_name({sample_name_server, hoge}).
ok

> local:whereis_name({sample_name_server, hoge}).
undefined


%% Stops name server
> ok = local:stop_name_server(sample_name_server).
> local:which_name_servers().
[]

Embedded Mode

Local can be embedded in your application.

%% Embedding Example
-module(your_app_sup).

-behaviour(supervisor).

-export([init/1]). % 'supervisor' callback API

init([]) ->
    Child1 = local:name_server_child_spec(your_app_name_server_1),
    Child2 = local:name_server_child_spec(your_app_name_server_2),
    {ok, { {one_for_one, 5, 10}, [Child1, Child2]} }.

couchdb-local's People

Contributors

sile avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.