src: Add optional completion callback

Add an optional callback argument which takes a function and is
triggered upon completion of the heap dump.