SpiderStrategies / node-gmail-api

Node module to interact with the gmail api
ISC License
154 stars 29 forks source link

Closing the stream #30

Open richburdon opened 7 years ago

richburdon commented 7 years ago

This may relate to my inexperience with streams, but I would expect the my simple test app to terminate after consuming the "finish" stream event? I know I can call process.exit, but the fact that it doesn't exit concerns me that some resource (request socket?) is being left open (and could accumulate/leak on subsequent calls?)

let gmail = new Gmail(ACCESS_TOKEN);
let stream = gmail.messages('label:inbox', { max: 10, fields: ['id', 'labelIds', 'snippet'] });
stream.on('data', (message) => {
  console.log(JSON.stringify(data));
});
stream.on('finish', () => {
  console.error('## PROCESS STAYS RUNNING ##');
});

I see the retrieve method calls combined.end() so I can't figure out why the process doesn't exit after the stream is closed.

CaptainJimmy commented 6 years ago

i'm having issues as well with trying to get the stream to close...it's playing havoc with a promise i need. Any movement on this @spider-dev ?

CaptainJimmy commented 6 years ago

i fixed this by round hole, square peg, big ugly hammer ... i just use recursion and a counter to find when the stream was supposed to close, and forced it to close...