New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

result-core

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

result-core

minimal result reification

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
205
decreased by-27.82%
Maintainers
1
Weekly downloads
 
Created
Source

result-core

JavaScript doesn't allow you to spawn new threads. Nore does it allow you to park a thread progamatically. Instead it uses an "event loop", which functions as a sort of work queue. It allows you to request an operation and register a function to be called when its completed. This function is called a "callback" and it provides all the synchronisation we need to compose computations however it leaves our control flow model FUBAR. Normally we think of values and errors as propagating up and down an implicit call stack. When a child computation completes it is returned to its parent frame where it can be passed into other computation frames or simply ignored and allowed to propagate up the stack. Meanwhile, in the "event loop" model values/errors are passed in to the callbacks as arguments which means both that they never become available in the parent context and that they can't just be allowed to propagate. Also without callstack's our error objects are mostly garbage.

Results are an attempt to re-build the call stack conceptual model back on top of the "event loop" model. The approach they take is to ask you to reify your asynchronous function calls with a Result instance. The intention of these is to model stack frames, in that they will eventually be either a successfully computed value or an error. Because these Result instances are runtime objects you can compose them together to recreate the computation tree that is normally implicit and maintained underneath the runtime.

This implementation does nothing to improve the stack traces of your errors but that feature could be added.

Installation

With component, packin or npm

$ {package mananger} install jkroso/result-core

then in your app:

var Result = require('result-core')

API

Result()

A class for creating concrete representations of function calls which can be manipulated programmatically at run-time.

function add(a, b){
  var result = new Result
  result.write(a + b)
  return result
}

add(1, 2).read(function(n){
  console.log('1 + 2 = %d', n)
})

Result.write(value)

give this its value

Result.error(reason)

give this its reason for failure

Result.read([onValue], [onError])

access the result of this

Running the tests

Just run make. It will install and start a development server so all you then need to do is point your browser to localhost:3000/test. Likewise to run the Koans.

Keywords

FAQs

Package last updated on 05 Sep 2013

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