You are reading a single comment by @PaddeK and its replies. Click here to read the full conversation.
  • I guess you are right @Gordon in terms of performance impact. But RAM is still an issue i guess because its very precious :)

    I have a sweet little example for the Map vs. Object point @opichals made before.
    Should be self-explanatory.

    'use strict';
    
    let sequence = (...map) => (ok, nok) => {
            map = new Map(map.map(e => Array.isArray(e) ? e : [e]));
            ok(Array.from(map.keys()).reduce((all, prm) => {
                return all.then(res => prm.then(data => res.set(prm, (map.get(prm) || (() => data))(data))).catch(nok));
            }, Promise.resolve(map)));
        };
    
    let add = num => num + 1;
    let mul = num => num * 2;
    let addPromise = num => Promise.resolve(num);
    let mulPromise = num => Promise.resolve(num);
    
    let adding = addPromise(10);
    let multing = mulPromise(20);
    
    let map = [adding,[multing, mul]];
    
    new Promise(sequence(...map)).then(result => {
        console.log('result', {addResult: result.get(adding), mulResult: result.get(multing)});
    }).catch(console.log.bind(null, 'error'));
    
About

Avatar for PaddeK @PaddeK started