Skip to content

Commit 91cf3f2

Browse files
committed
Defer running lines until the next tick and fix load behavior
1 parent d683f04 commit 91cf3f2

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

lib/node_modules/@stdlib/repl/lib/commands/load.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
var logger = require( 'debug' );
2626
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
27-
var noop = require( '@stdlib/utils/noop' );
28-
var displayPrompt = require( './../display_prompt.js' );
2927

3028

3129
// VARIABLES //
@@ -60,14 +58,38 @@ function command( repl ) {
6058
repl._ostream.write( 'Error: '+err.message+'\n' );
6159
return;
6260
}
63-
// Reset the display prompt:
64-
repl._rli.write( '\n' );
65-
displayPrompt( repl, false );
66-
67-
// FIXME: fix error handling here (e.g., file does not exist, etc)
61+
repl.once( 'drain', onDrain );
62+
63+
/**
64+
* Callback invoked upon a 'drain' event.
65+
*
66+
* @private
67+
*/
68+
function onDrain() {
69+
try {
70+
debug( 'Loading a file...' );
71+
repl.load( fpath, clbk );
72+
} catch ( error ) {
73+
debug( 'Error: %s', error.message );
74+
75+
// TODO: determine whether we need to perform ANSI escape magic here! (the error message gets printed on the wrong line!)
76+
repl._ostream.write( 'Error: '+error.message+'\n' );
77+
}
78+
}
6879

69-
debug( 'Loading a file...' );
70-
repl.load( fpath, noop );
80+
/**
81+
* Callback invoked upon loading a file.
82+
*
83+
* @private
84+
* @param {Error} [error] - error object
85+
*/
86+
function clbk( error ) {
87+
if ( error ) {
88+
debug( 'Error: %s', error.message );
89+
return;
90+
}
91+
debug( 'Successfully loaded file.' );
92+
}
7193
}
7294
}
7395

lib/node_modules/@stdlib/repl/lib/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ setNonEnumerableReadOnly( REPL.prototype, 'load', function load( fpath, clbk ) {
609609
// Forward each line to the REPL readline interface in order to mimic user input...
610610
len = file.length;
611611
i = -1;
612-
return next();
612+
613+
// TODO: replace with polyfill
614+
process.nextTick( next );
613615

614616
/**
615617
* Callback invoked after draining the command queue.

0 commit comments

Comments
 (0)