Note: I am using domainit to execute tasks I don't control in a consistent and hopefully safer fashion.
Whether or not Event Emitters make sense here was the gray area that made me post this thread. Pedro, your response was really helpful for me to clearly describe the use-case this module is intended to resolve, thanks! The domains API is powerful enough to handle a variety of scenarios. Domainit is meant to simplify one scenario: a finite task that may involve async work and, assuming no unhandled errors, notifies of completion through a standard callback function. I see domainit as a way of wrapping the execution of a potentially async, potentially failing operation in a conceptual try-catch while keeping true to the node standard callback conventions. The intention is to execute the callback exactly once. Matt & 3rdEden: I am aware of bind(). If the caller already had a domain instance handy, then that might make sense; otherwise, the caller needs to create a domain and attach to the error event. Furthermore, if the task being performed subsequently invokes your callback, your callback will be executed in the context of that task's domain. For this scenario, the domain's error handler wasn't likely meant to deal with errors in your callback - just errors in the task. You likely want a higher-level domain's error handler or the process' uncaughtException handler dealing with this. In my opinion, wrapping the unsafe function and using the standard callback approach makes things more composable. You could pass the resultant function to something like async.parallel, for instance. Cheers, Mario Pareja On Thursday, 4 April 2013 10:31:58 UTC-4, 3rdEden wrote: > > because that makes to much sense? > > On Thursday 4 April 2013 at 15:20, Matt wrote: > > Why not just use domain.bind() on the function? > > > On Thu, Apr 4, 2013 at 8:54 AM, Pedro Teixeira > <[email protected]<javascript:> > > wrote: > > I think it may be misleading, since that function is not a callback in the > sense that it will not be called *once* and that there is no operation that > has a definitive end. > > I think that an Event Emitter here is more standard and would play better > with others. > > -- > Pedro > > On Thursday, April 4, 2013 at 7:54 AM, Mario Pareja wrote: > > I wrote a little module <https://github.com/mpareja/node-domainit>because it > allows me to execute a function that I don't control and handle > errors in a simple, uniform way. Do you all think that using a standard > callback style here makes sense? Or is this completely asinine because of > some intricacy of domains that I missed? > > I've included the README below for your reading pleasure. > > Cheers, > > Mario Pareja > > > domainit - wrap a function with the safety of a domain > > Wrap a function with the warm comfort of a node domain using standard > callbacks. > > var assert = require('assert');var domainit = require('domainit'); > function unsafe(cb) { > process.nextTick(function () { > throw new Error('Oops!'); > });} > var safe = domainit(unsafe);safe(function (err) { > assert(err); > assert(err.message === 'Oops!');}); > > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] <javascript:> > To unsubscribe from this group, send email to > [email protected] <javascript:> > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] <javascript:> > To unsubscribe from this group, send email to > [email protected] <javascript:> > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] <javascript:> > To unsubscribe from this group, send email to > [email protected] <javascript:> > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] <javascript:>. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
