From 9c5900b69388566bb7bed0ba144eb730a74b4d72 Mon Sep 17 00:00:00 2001 From: Aldwin Vlasblom Date: Wed, 7 Jun 2017 13:40:36 +0200 Subject: [PATCH] Use ducktyping in interpretor to determine whether to flat map This allows the interpretor to be a static export without dependency injection, but more importantly, it allows the interpretor to absorb Futures produced by actions which return Futures created by another compatible version of Fluture. --- src/core.js | 2 +- src/internal/interpretor.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core.js b/src/core.js index d8efa4fc..fce2b5bf 100644 --- a/src/core.js +++ b/src/core.js @@ -560,7 +560,7 @@ Sequence.prototype._finally = function Sequence$finally(other){ return this._transform(new FinallyAction(other)); }; -Sequence.prototype._fork = interpretor(Sequence); +Sequence.prototype._fork = interpretor; Sequence.prototype.toString = function Sequence$toString(){ return `${this._spawn.toString()}${this._actions.map(x => `.${x.toString()}`).join('')}`; diff --git a/src/internal/interpretor.js b/src/internal/interpretor.js index 3379924c..75b15eef 100644 --- a/src/internal/interpretor.js +++ b/src/internal/interpretor.js @@ -3,7 +3,7 @@ import Denque from 'denque'; import {noop} from './fn'; -export default Sequence => function interpretor(rej, res){ +export default function interpretor(rej, res){ //This is the primary queue of actions. All actions in here will be "cold", //meaning they haven't had the chance yet to run concurrent computations. @@ -29,7 +29,7 @@ export default Sequence => function interpretor(rej, res){ function settle(m){ settled = true; future = m; - if(future instanceof Sequence){ + if(future._spawn){ for(let i = future._actions.length - 1; i >= 0; i--) cold.unshift(future._actions[i]); future = future._spawn; } @@ -123,4 +123,4 @@ export default Sequence => function interpretor(rej, res){ while(it = queue.shift()) it.cancel(); }; -}; +}