minimal result reification
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.
npm install result-core
then in your app:
import Result from 'result-core'
A class for creating concrete representations of function calls.
state can be one of:
All Results start of in a "pending" state and will transition either to "done" or "fail".
'pending'state // => 'pending'
The value of the Result. If the Result has a state of "fail" then this value is an error. If its "pending" then reading its value is useless. You should use the read method unless you know what your doing and are handling each of the 3 possible states correctly.
var result = 'pending'resultwritea + breturn resultadd1 2value // => 3
give the Result its value and change its state to "done"
var one = 'pending'write1onestate // => 'done'onevalue // => 1
give the Result its error and change its state to "fail"
var err = 'coz oops'var two = 'pending'.errorerrtwostate // => 'fail'twovalue // => err
access the result of
onereadn => n /* n = 1 */ // error handlers are optionaltworeadnull // value handlers are also optionale => e // => err