Use of {continue, _} in gen_server's init

One example would be to start multiple children concurrently. Imagine this supervision tree:
myapp_sup → [child1, child2, child3]. All of them are independent (so, myapp_sup is one_for_one). They are all slow to init (for example, read large files - translations, IP to ASN mappings, phone number mapping etc.).

So we have children loading files in handle_continue. All 3 children are initialising concurrently, and total startup time is equal to the longest of the 3 - not the sum of these 3.

Pretty much any asynchronous work that shouldn’t fail gen_server supervised startup can be done there. Say, if it’s a cache (I should probably open source gen_cache behaviour we’ve been using internally for quite a long time), then cache warm-up can happen in handle_continue (because cold cache can be already utilised - via ETS - by other processes).

4 Likes