audreyt / node-webworker-threads

Lightweight Web Worker API implementation with native threads
https://npmjs.org/package/webworker-threads
Other
2.3k stars 149 forks source link

Problem in calling FileSystem API node.js #117

Closed NickNaso closed 8 years ago

NickNaso commented 8 years ago

Hi, i've a problem when call a FileSystem API in a WebWorker-Threads, in particular my seems that function is not executed. Is there a restriction about that? Ths is my code:

'use strict';
const fs = require('fs');
const Worker = require('webworker-threads').Worker
// some other stuff ...
app.post('/myRoute', function (req, res, next) {
  // some other stuff ...
  const myWorker = new Worker(function () {
   function myTask(data) {
     // some other stuff ...
     try {
       let myPath = data.path;
       fs.mkdirSync("myPath");
       return data;
     } catch(e) {
       data.error = e;
       return data;
     }
   }
   this.onmessage = function (event) {
     postMessage(myTask(event.data));
   }
 });
 myWorker.onmessage = function (event) {
   // some other stuff to set response
   res.send(.......);
 }
 myWorker.postMessage(data);
});

My application is bulded using express.js and all is fine unitl i do not call fs.mkdirSync or other function of FileSystem API, infact when i use that as in above example the system do not finish to process my request. Maybe i cannot use FileSystem API in WebWorke-Thread or i use it in a bad way. Thaks all to any help. Nick

audreyt commented 8 years ago

That is correct, we currently do not expose the fs API.

loganpowell commented 6 years ago

Sorry for pinging on a closed issue, but are there any plans to provide access to Node fs at some point?

audreyt commented 6 years ago

Not at the moment. (Pull requests are welcome as usual.)