A way to create read-eval-print-loops for your own projects, with a per-instance history, rather than a global history.
const customRepl = require('./custom-repl.js');
/**
* Add context to the REPL:
* What things are accessible from the prompt?
*/
const foobarRepl = customRepl('foobar');
function syncThing (x) {
return `sync ${x}`;
}
function asyncThing (x) {
return `async ${x}`;
}
// add synchronous context
fooBarRepl.addContext(syncThing);
// add asynchronous context
setTimeout(() => {
foobarRepl.addContext(asyncThing);
}, 5000);
- You may run
syncThing()
immediately - You need to wait five seconds before you may run
asyncThing()
- IRL, you would do this to wait for something that is asynchronous to finish loading, or similar