mixpanel / mixpanel-node

A node.js API for mixpanel
http://www.mixpanel.com
MIT License
475 stars 161 forks source link

Using promises #230

Open shareefhadid opened 5 months ago

shareefhadid commented 5 months ago

This package should really be using promises as most calls are asynchronous.

This wasn't made clear in the documentation, but I realized it when I performed an expensive operation and the connection closed before it could be completed.

For now I need to wrap the calls in promises myself and resolve/reject in the callback like so:

await new Promise((resolve, reject) => {
  mixpanel.people.set_once(identifier, data, (e) => {
    if (e) {
      reject(e);
    }

    resolve(null);
  });
}
vsnthdev commented 3 months ago

I was using this on Vercel Serverless functions, and events weren't reflecting on the dashboard. After doing some investigation, turns out the serverless function closes even before a request is fully made.

Thanks for the solution @shareefhadid