Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

outcome

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

outcome

Better Result Handling

  • 0.0.1
  • npm
  • Socket score

Version published
Weekly downloads
8.6K
decreased by-9.27%
Maintainers
1
Weekly downloads
 
Created
Source

Old Way

var fs = require('fs');

fs.stat('some/file.js', function(err, result) {
	
	if(err) {
		//do stuff, or throw
		return;
	}


	//do success stuff
});

Outcome API

There are two ways you can use outcome.js:



var onOutcome = outcome().result(function() {
	
	console.log('result');

}).error(function() {
	
	console.log('error');	
});


fs.stat(__filename, onOutcome);

Or


outcome.call(fs.stat, __filename).result(function() {

	console.log("RESULT");

}).error(function() {
	
	console.log("ERROR");

})

.outcome([listenersOrEm])

  • listenersOrEm - listeners or eventEmitter
var em = new EventEmitter();

em.on('result', function() {
	console.log("RESULT");
});

fs.stat(__filename, outcome(em));

Or

var onOutcome = outcome({
	result: function() {
		console.log("RESULT");
	},
	error: function() {
		console.log("ERROR");
	}
});

fs.stat(__filename, onOutcome);

By default, any unhandled errors are thrown. To get around this, you'll need to listen for an unhandledError:

outcome.on('unhandledError', function(error) {
	//report bugs here..., then throw again.
});


fs.stat(outcome({
	result: function(){}
}));

CallChain .call(fn[, arg1][, arg2][, ...])

Calls the given function

  • fn - target function to be called
  • target - target scope - for this
outcome.call(fs.stat, null, fs).on({
	error: function() { },
	result: function() { }
});

//or
outcome.call(fs.stat, fs, {
	error: function() { },
	result: function() { }
})

CallChain .on(typeOrEvents[, callback])

Listens for any events emitted by outcome - primarily unhandledError

  • typeOrEvent - type of event (string), or object of events
  • callback - callback for the listener
outcome.on('unhandledError', function() {
	//DO STUFF
});

CallChain .listen(EventEmitter[, events])

Listens to the given event emitter.

outcome.listen(em).on({
	someEvent: function(){}
});

//or

outcome.listen(em, {
	someEvent: function(){}
});

CallChain .emit(EventEmitter)

Pipes events to target event emitter

outcome.call(fs.stat).emit(em);

CallChain .done()

Called when on error/result:

outcome.call(fs.stat, {
	result: function() {
		
	}
}).done(function(err, result) {
	
});

CallChain .result(fn)

Called on success/result

outcome.call(fs.stat).result(function(result) {
	
});

CallChain .error(fn)

Called on error

outcome.call(fs.stat).error(function(err) {
	//handle error
});

CallChain API

Same as as above

CallChain .on(typeOrEvents[, callback])

Listens for results - error, and result primarily.

  • typeOrEvent - type of event (string), or object of events
  • callback - callback for the listener
outcome.call(fs.stat).on('error', function() {
	
}).on('result', function() {
	
});

//or 

outcome.call(fs.stat).on({
	error: function() {},
	result: function() {}
})

FAQs

Package last updated on 23 Dec 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc