# When do you use handle\_continue?

**URL:** <https://erlangforums.com/t/when-do-you-use-handle-continue/950>\
**Category:** Chat / Discussions\
**Tags:** otp, handle\_continue, gen\_servers\
**Created:** [January 19, 2022, 12:01pm UTC](https://erlangforums.com/t/when-do-you-use-handle-continue/950 "2022-01-19T12:01:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirWerto](https://erlangforums.com/user_avatar/erlangforums.com/sirwerto/32/2936_2.png) [@SirWerto](https://erlangforums.com/u/SirWerto)\
**Post date:** [January 19, 2022, 12:01pm UTC](https://erlangforums.com/t/when-do-you-use-handle-continue/950/1 "2022-01-19T12:01:00Z")

</div>

Good afternoon,

I have recently started using `handle_continue` on my `gen_servers`. I am using it for returning the `init` callback as soon as possible and perform initialisation task on it, also, it is the responsible of handling db storage tasks.

Is `handle_continue` necessary if you don’t have too much pressure?

Where do you use it?

---

<div class="post-metadata">

**Author:** ![domi](https://erlangforums.com/user_avatar/erlangforums.com/domi/32/263_2.png) [@domi](https://erlangforums.com/u/domi)\
**Post date:** [January 19, 2022, 12:18pm UTC](https://erlangforums.com/t/when-do-you-use-handle-continue/950/2 "2022-01-19T12:18:52Z")

</div>

If you need to perform some work post-init, it’s handy to avoid the race condition described in this issue: [Add info returns to gen\_server by josevalim · Pull Request #1429 · erlang/otp · GitHub](https://github.com/erlang/otp/pull/1429#issue-224294901).

---

<div class="post-metadata">

**Author:** ![SirWerto](https://erlangforums.com/user_avatar/erlangforums.com/sirwerto/32/2936_2.png) [@SirWerto](https://erlangforums.com/u/SirWerto)\
**Post date:** [January 19, 2022, 12:52pm UTC](https://erlangforums.com/t/when-do-you-use-handle-continue/950/3 "2022-01-19T12:52:50Z")

</div>

Extremely interesting, thanks!!

---

<div class="post-metadata">

**Author:** ![srijan](https://erlangforums.com/user_avatar/erlangforums.com/srijan/32/656_2.png) [@srijan](https://erlangforums.com/u/srijan)\
**Post date:** [January 20, 2022, 5:19pm UTC](https://erlangforums.com/t/when-do-you-use-handle-continue/950/4 "2022-01-20T17:19:33Z")

</div>

From [Erlang -- gen\_server](https://www.erlang.org/doc/man/gen_server.html#Module:handle_continue-2:)

> `handle_continue/2` is invoked immediately after the previous callback, which makes it useful for performing work after initialization or for splitting the work in a callback in multiple steps, updating the process state along the way.

If we try to break down these two use cases:

1. **Performing working after initialization** : This can be used to make sure that some post-init work is definitely completed before the `gen_server` goes into any other callback.

2. **Splitting work in a callback in multiple steps** , updating the process state along the way.

---

<div class="post-metadata">

**Author:** ![phild](https://erlangforums.com/user_avatar/erlangforums.com/phild/32/742_2.png) [@phild](https://erlangforums.com/u/phild)\
**Post date:** [January 22, 2022, 5:32pm UTC](https://erlangforums.com/t/when-do-you-use-handle-continue/950/5 "2022-01-22T17:32:47Z")

</div>

I’m using it in a distributed 2 node system in order to wait until a socket is closed before trying to open it on the node that is taking over. However, what I really want to do is pass control of the socket to the other node. Still working on that one. It’s probably pointless as (unlike failover) I don’t have a real world use case for takeover other than proving I can.
