sculejs icon indicating copy to clipboard operation
sculejs copied to clipboard

add support for callbacks on I/O bound operations

Open deyles-zz opened this issue 12 years ago • 5 comments
trafficstars

At the moment there is no facility to provide callbacks on I/O bound operations such as loading data from disk - we need to add this functionality. An example might be:

sculedb.factoryCollection('scule+nodejs://collection', {secret:'test', path:'/tmp'}, function(err, data) {
   // do something with err or data here
});

It'd also be good to normalize callbacks on existing non-blocking functions to use the same signature and passing error objects rather than throwing them:

collection.count({i:{$gte:5000}, n:{$lte:80}}, {}, function(err, data) {
   if (err) {
      // handle error
   }
   // handle data
});

deyles-zz avatar Jun 15 '13 12:06 deyles-zz

Hi! Is that in progress?

nuh-temp avatar Nov 11 '13 23:11 nuh-temp

Hey Anush, this is coming in the next stable release, probably in the next week or so :-)

deyles-zz avatar Nov 14 '13 08:11 deyles-zz

Good news! Because it's required by the my project and I'm about to add it by myself.

nuh-temp avatar Nov 14 '13 15:11 nuh-temp

Hi Dan, is this going to be fixed any time soon? I would like to use sculejs for storing data in nodejs application (using nodejs storage engine) and current approach of throwing exception upon error in asynchronous IO callback makes sculejs pretty much unusable in such environment since it's not possible to handle errors from reads/writes.

What I would need is that all user provided callbacks are called with (error, result) arguments and remove all exception throws from read/write storage engine operations. I guess this will required change of major revision number for sculejs npm package as it is backward incompatible change.

jkryl avatar Feb 25 '14 10:02 jkryl

There should now be callbacks available on all IO bound operations, however they don't follow the convention of f(err, result). Since this will likely be a breaking change for most users I'll introduce that convention in v0.2.0 along with a promise based interface to the Database and Collection classes.

deyles-zz avatar Jul 18 '15 07:07 deyles-zz