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.3
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Old Way

var fs = require('fs');

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


	//do success stuff
});

Outcome API

.outcome(listeners)

  • listeners - success, or error


var resultHandler = outcome.error(function(err) {
	console.log(err);
});

//success
fs.stat(__filename, resultHandler.copy().success(function(data) {
	//do stuff
}));

//success
fs.stat(__filename, resultHandler.copy().success(function(data) {
	//do stuff
})); 

//this fails - error is passed to above func
fs.stat('s'+__filename, resultHandler.copy().success(function(data) {
	//do stuff
})); 


Or

var onOutcome = outcome({
	success: function() {
		console.log("SUCCESS");
	},
	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.
});


//fails
fs.stat('s'+__filename, outcome({
	success: function(){}
}));

.copy()

Copies the current call chain. Useful for using one error handler, and many result handlers. See first example.

.done()

Called when on error/success. Same as function(err, data) { }


fs.stat(__filename, outcome.error(function(err) {
	//handle error
}).success(function(data) {
	//handle result
}.done(function(err, result) {
	//called on fn complete
});

.success(fn)

Called on success

var onOutcome = outcome.success(function(data) {
	
});

onOutcome(null, "success!");

.error(fn)

Called on error


var onOutcome = outcome.error(function(err) {
	
});

onOutcome(new Error("ERR"));

.handle(fn)

Custom response handler


outcome.handle(function(response) {
	
	if(response.errors) this.error(response);
	if(response.data) this.success(response);
});

FAQs

Package last updated on 31 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