Fixing error related to usage this.global.ended and also removing deprecated usage of on('end') for the async writer