export function unpromisify ( func , success , failure ? ) { let isResolved = false ; let wrappedSuccess = function ( ) { if ( ! isResolved ) { isResolved = true ; success . apply ( this , arguments ) ; } } ; let wrappedFailure = function ( ) { if ( ! isResolved ) { isResolved = true ; if ( failure ) { failure . apply ( this , arguments ) ; } } } ; let res = func ( wrappedSuccess , wrappedFailure ) ; if ( res && typeof res . then === 'function' ) { res . then ( wrappedSuccess , wrappedFailure ) ; } }