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'));
@PaddeK started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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.