Change to use Promise instead of Deferred in code gen