From 3915201aad0dd9e56b0b774e23acef446c77deed Mon Sep 17 00:00:00 2001 From: Mark Eschbach Date: Wed, 12 Feb 2020 09:28:46 -0800 Subject: [PATCH] [breaking] junk-bucket/future now exports Future as a component of the module --- future.js | 10 ++++++---- rpc.js | 2 +- sequence.js | 17 ++++++++++------- sockets.js | 2 +- streams.js | 2 +- tests/future-tests.js | 2 +- tests/sequence-tests.js | 2 +- tests/spool-tests.js | 2 +- timers.js | 2 +- 9 files changed, 23 insertions(+), 18 deletions(-) diff --git a/future.js b/future.js index 81a1919..e296291 100644 --- a/future.js +++ b/future.js @@ -114,7 +114,9 @@ async function parallel( promises ){ return out.good; } -module.exports = Future -module.exports.delay = delay; -module.exports.promiseEvent = promiseEvent; -module.exports.parallel = parallel; +module.exports = { + Future, + delay, + promiseEvent, + parallel +}; diff --git a/rpc.js b/rpc.js index c24abc4..90e4b76 100644 --- a/rpc.js +++ b/rpc.js @@ -1,5 +1,5 @@ const {Dispatcher, Base36Namer} = require("./command-dispatcher"); -const Future = require("./future"); +const {Future} = require("./future"); class RPCClient { constructor(input, output) { diff --git a/sequence.js b/sequence.js index f7fe2c7..c431775 100644 --- a/sequence.js +++ b/sequence.js @@ -1,15 +1,18 @@ -const Future = require('./future') -const assert = require('assert') +/** + * An abstraction around time bound delayed execution of a series of promises. + */ +const {Future} = require('./future'); +const assert = require('assert'); class Sequence { constructor( initialValue = true ) { - const when = new Future() + const when = new Future(); when.accept(initialValue); this.last_op = when.promised; } next( perform ){ - assert.equal(typeof perform, "function") + assert.equal(typeof perform, "function"); const operation = this.last_op.then(( input ) => { return perform( input ) }); @@ -25,11 +28,11 @@ class Sequence { canceled = true; fail() } - }) + }); this.next( (input) => { if( canceled ){ return input; } waiting = false; - clock.cancel(token) + clock.cancel(token); return perform( input ) }); } @@ -37,4 +40,4 @@ class Sequence { module.exports = { Sequence -} +}; diff --git a/sockets.js b/sockets.js index fcbf7a4..6b6ab21 100644 --- a/sockets.js +++ b/sockets.js @@ -1,4 +1,4 @@ -const Future = require("./future"); +const {Future} = require("./future"); /** * Abstracts out how to retrieve an address of a socket when being bound as a listener. The resulting socket is the diff --git a/streams.js b/streams.js index 624a310..3829e6e 100644 --- a/streams.js +++ b/streams.js @@ -1,4 +1,4 @@ -const Future = require("./future"); +const {Future} = require("./future"); const {Readable, Transform, Writable} = require("stream"); const {LengthPrefixedFrameIngress, LengthPrefixedFrameEgress} = require("./streams/network-length-frame"); diff --git a/tests/future-tests.js b/tests/future-tests.js index f4cb1fc..3c056f5 100644 --- a/tests/future-tests.js +++ b/tests/future-tests.js @@ -1,6 +1,6 @@ const mocha = require("mocha") const assert = require("assert") -const Future = require("../future") +const {Future} = require("../future"); describe( "Future", function () { diff --git a/tests/sequence-tests.js b/tests/sequence-tests.js index 79b693f..b5c4b7e 100644 --- a/tests/sequence-tests.js +++ b/tests/sequence-tests.js @@ -2,7 +2,7 @@ const mocha = require("mocha") const assert = require("assert") const {Sequence} = require('../sequence') -const Future = require('../future') +const {Future} = require('../future'); describe("Sequence", function () { it("initial value is passed to first in sequence", async function(){ diff --git a/tests/spool-tests.js b/tests/spool-tests.js index acaf9af..b6e6bba 100644 --- a/tests/spool-tests.js +++ b/tests/spool-tests.js @@ -1,7 +1,7 @@ const mocha = require("mocha") const assert = require("assert") -const Future = require("../future") +const {Future} = require("../future"); const {Sequence} = require('../sequence') const {LogicalTimer, WatchDog, defaultNodeTimer} = require("../timers") diff --git a/timers.js b/timers.js index 9df4a08..e926376 100644 --- a/timers.js +++ b/timers.js @@ -1,4 +1,4 @@ -const Future = require('./future') +const {Future} = require('./future'); const assert = require('assert') class LogicalTimerAlarm {