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

iox

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iox - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

coverage/clover.xml

63

iox.js
// @flow
//
// Refactoring simulate()
// - To see if I can break down the individual functions
// - I don't like the switch statement. It could even be a hashmap

@@ -13,38 +9,15 @@ /*::

const readEventFromQueue = then => ({ io : 'read-event-from-queue', then });
const writeToDisk = (value, then) => ({ io : 'write-to-disk', value, then });
const log = (m, then=() => 1) => ({ io : 'log', m, then });
function someProcess() /*:IO*/ {
return readEventFromQueue(event => {
if (event === 'END') {
return 'The meaning of life is 41.99999999...';
}
return writeToDisk(event + ' received', _ =>
log('Written event to disk: ' + event, someProcess)
);
});
}
function makeSimulator() /*:Actions*/ {
const events = ['first event', 'second event', 'END'];
return {
'read-event-from-queue': io => events.shift(),
'write-to-disk': io =>
new Promise((resolve, reject) => setTimeout(x => resolve('👍'), 2000)),
log: io => console.log('logging', io)
};
}
function isIO(value /*: IO | mixed */) {
return Boolean(
!!value &&
value != null &&
typeof value === 'object' &&
typeof value.io === 'string' &&
typeof value.then === 'function'
(!value.then || typeof value.then === 'function')
);
}
module.exports.run = run;
function identity(x) {
return x;
}
function run(actions /*:Actions*/, value /*:IO*/) {

@@ -56,16 +29,18 @@ while (true) {

const io /*:IO*/ = value;
const ioFunc = actions[io.io];
if (ioFunc == null) throw new Error('Unknown io operation' + value.io);
const next = ioFunc(io);
if (next instanceof Promise)
return next.then(io.then).then(v => run(actions, v));
else value = io.then();
// Execute io.action
const action = actions[io.io];
if (action == null) throw new Error('Unknown io operation: ' + value.io);
const next = action(io);
// Call io.then with the result.
const then = io.then || identity;
if (next instanceof Promise) {
return next.then(then).then(v => run(actions, v));
} else {
value = then(next);
}
}
}
// run(makeSimulator(), writeToDisk('x', r=>r)).then(console.log)
//run(makeSimulator(), log('⧴', _=>writeToDisk('x', r=>r))).then(console.log)
run(makeSimulator(), log('⧴', _ => writeToDisk('x', log))).then(r => console.log('r:', r))
//console.log(result);
module.exports.run = run;
{
"name": "iox",
"version": "0.0.1",
"version": "0.0.2",
"main": "iox.js",

@@ -8,7 +8,20 @@ "repository": "git@github.com:pokle/iox.git",

"license": "MIT",
"dependencies": {
"scripts": {
"test": "jest --coverage"
},
"dependencies": {},
"devDependencies": {
"jest": "21.2.1"
"jest": "21.2.1",
"jsverify": "0.8.3"
},
"jest": {
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
}
}
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