Callbacks: new internal resolve function
Callbacks: new internal resolve function

Lwt's internal [resolve] function does two things:

- Sets the state of a pending promise to either Fulfilled or Rejected.
- Calls all the callbacks that were attached to the promise while it was
  still pending.

The old version of this function unconditionally called the callbacks
immediately. The version added in this commit first checks the current
callback nesting depth. If the depth exceeds a limit, callbacks are
deferred into a queue instead of being called right away.

To support the old behavior until Lwt 4.0.0, the new function has an
[?allow_deferring] optional argument that can be set to [false]. If so
set, callbacks are not deferred, even if the nesting limit is exceeded.

To support the old behavior of specifically [Lwt.wakeup_later], the new
[resolve] function has a [?maximum_callback_nesting_depth] optional
argument. [Lwt.wakeup_later] sets this to 1.

The old [resolve] could only be safely called during an already-started
resolution loop, i.e. inside a surrounding [run_in_resolution_loop]
call. To statically ensure this, a dummy [in_resolution_loop] value was
passed around Lwt, and the old [resolve] could only be called from
contexts where [in_resolution_loop] was available.

The new [resolve] enters the resolution loop on its own. Indeed, this is
part of tracking the callback nesting depth. As a result, the
[in_resolution_loop] safety mechanism is no longer necessary, and it is
removed by this commit.

ocsigen/lwt,c-cube/lwt,ocsigen/lwt,c-cube/lwt,c-cube/lwt,rneswold/lwt,rneswold/lwt,rneswold/lwt,ocsigen/lwt