Revertable
// place where we can show side effects//// -- this generally would be the fs or some// outside systemvar state = {}; // creating a revertable is just creating a// function to perform an action, and the inversevar revertableInstance = { var key = Math; statekey = 1; return Promise; } { delete statekey; return Promise; }; // revertables do not automatically perform their function// so we should invoke it and wait for it to finishvar successfulPromise = revertableInstance;var dataNeededToRevert;successfulPromise;
Series
Sometimes we need to create a revertable that performs multiple actions.
We can do this by creating an array of revertables and using Revertable.series
to turn them into a single revertable.
Revertable.series([makeDir, writeFile]).attempt();
Branch
Sometimes we have a large list of tasks that can be performed in parallel.
We can support this by using Revertable.branch
similar to series.
Revertable.branch([writeToCache, writeToDB]).attempt();