Chaining of functions call to resolve the problem of javascript async callback handling