koltyakov / sppull

📎 Download files from SharePoint document libraries using Node.js without hassles
MIT License
46 stars 16 forks source link

SPPull singleton error with mutable shared state #33

Closed chrishasz closed 5 years ago

chrishasz commented 5 years ago

OK, so the title is a bit of a mouthful, but here is what I am experiencing:

When I use a RegEx pattern to filter downloads, and issue multiple simultaneous sppull requests, whichever RegEx pattern is specified for the last sppull request will be used across all requests. This is because the options object in the SPPull singleton is shared and last-in wins. There is actually a race condition across any property on the options object, but the fileRegExp object consistently fails, because the value is not accessed until after a roundtrip (or more) to the server.

Would it be possible to export the Download class separately, separately from the singleton (for backwards compatibility) so that I can instantiate multiple instances of it, each with their own state?

here is the code from SPPull.js which creates the singleton:

import { Download } from './SPPull';

export { ISPPullOptions, ISPPullContext, Download } from './SPPull';

const sppull = new Download();
module.exports = sppull;

Possibly related to this issue

koltyakov commented 5 years ago

Hi @chrishasz, Thanks! Got the point. Let me think what can I do. Going to refactor SPPull.ts as well.

koltyakov commented 5 years ago

@chrishasz applied the fix. Please check if it works for you. Published v2.4.0.

chrishasz commented 5 years ago

Hello @koltyakov!

Thanks for the quick response! I've upgraded to SPPull 2.4.0 and initial testing looks great. I'll run a few more tests in the morning just to make sure, but I'll close this issue now.

Thank you!