diff options
author | Hans Bolinder <[email protected]> | 2016-04-01 13:01:04 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2016-04-01 13:01:04 +0200 |
commit | 2f0fa3806c9196f16bb49dc0ee3fbc4737eea23f (patch) | |
tree | ad781ce867b5de09a6c88127dbdab9ab4c89638c | |
parent | e31c6633233dc996d2ead18b479458b20e6ee5e8 (diff) | |
parent | 1ea5c627686b91a549da3ebee73170ac26915e4d (diff) | |
download | otp-2f0fa3806c9196f16bb49dc0ee3fbc4737eea23f.tar.gz otp-2f0fa3806c9196f16bb49dc0ee3fbc4737eea23f.tar.bz2 otp-2f0fa3806c9196f16bb49dc0ee3fbc4737eea23f.zip |
Merge branch 'sa/specs-for-callbacks'
* sa/specs-for-callbacks:
Add documentation about -specs for callbacks
-rw-r--r-- | system/doc/design_principles/spec_proc.xml | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/system/doc/design_principles/spec_proc.xml b/system/doc/design_principles/spec_proc.xml index 3d7a88da3f..5b156ac263 100644 --- a/system/doc/design_principles/spec_proc.xml +++ b/system/doc/design_principles/spec_proc.xml @@ -4,7 +4,7 @@ <chapter> <header> <copyright> - <year>1997</year><year>2014</year> + <year>1997</year><year>2016</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -522,9 +522,36 @@ init(Parent, Name, Module) -> -module(db). -behaviour(simple_server). --export([init/0, handle_req/2, terminate/0]). +-export([init/1, handle_req/2, terminate/0]). ...</code> + + <p>The contracts specified with <c>-callback</c> attributes in + behaviour modules can be further refined by adding <c>-spec</c> + attributes in callback modules. This can be useful as + <c>-callback</c> contracts are usually generic. The same callback + module with contracts for the callbacks:</p> + + <code type="none"> +-module(db). +-behaviour(simple_server). + +-export([init/1, handle_req/2, terminate/0]). + +-record(state, {field1 :: [atom()], field2 :: integer()}). + +-type state() :: #state{}. +-type request() :: {'store', term(), term()}; + {'lookup', term()}. + +... + +-spec handle_req(request(), state()) -> {'ok', term()}. + +...</code> + + <p>Each <c>-spec</c> contract is to be a subtype of the respective + <c>-callback</c> contract.</p> + </section> </chapter> - |