-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
Closed
Labels
cliIssues and PRs related to the Node.js command line interface.Issues and PRs related to the Node.js command line interface.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
Description
I've seen this requested a few times in StackOverflow now:
People have code that is asynchronous and would like to use values from it in the REPL:
// how do I access in the REPL? returns promise
Transaction.where('reference', '1').fetch().then((res) => { return res });
A common workaround is to store a global reference in the REPL, which is a little hacky and relies on timing, but can work for simple cases:
> Transaction.where('reference', '1').fetch().then((res) => out = res)
[Object Promise]
> out
/* response available here*/
This works, but has timing issues and generally isn't great. We could however run the REPL in the context of an async function potentially - which would allow await
ing values in the REPL:
let res = await Transaction.where('reference', '1').fetch();
I think it could be an interesting enhancement but would like more feedback on the idea. @nodejs/collaborators
not-an-aardvark, refack, crunchtime-ali, sindresorhus, bergus and 129 morechicoxyzzy and luiseduardobritopannous, AdrieanKhisbe, kothique, luiseduardobrito, trythrow and 2 morejunosuarez, raxod502, Gabriele-Tomberli, elcasu, AdrieanKhisbe and 9 moreExE-BossAntonioFerrandiz and Hydrophobefireman
Metadata
Metadata
Assignees
Labels
cliIssues and PRs related to the Node.js command line interface.Issues and PRs related to the Node.js command line interface.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.promisesIssues and PRs related to ECMAScript promises.Issues and PRs related to ECMAScript promises.replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.