-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
Hello good people of coffeescript:
Currently, the way I can test how a library that heavily rely on promises works on the REPL is as follow:
coffee> wikijs = require('wikijs')
coffee> batman = ""
coffee> wikijs().page('batman'). then (response)=> batman = response
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
coffee> batman
' ' // too soon.. the promise hasn't resolved yet
coffee> batman
{
links: [Function: links],
categories: [Function: categories],
coordinates: [Function: coordinates],
info: [Function: n],
backlinks: [Function: backlinks],
rawImages: [Function: f],
mainImage: [Function: mainImage]
}
coffee> mainImage = ''
coffee> wikijs().page('batman'). then (response)=> response.mainImage()). then ( img) => mainImage = img
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
coffee> mainImage
'https://upload.wikimedia.org/wikipedia/en/7/74/Batman_Detective_Comics_Vol_2_1.png'I can also define a function, but doing that on a REPL is awkward. I would rather create a file and set up an environment that auto run my script on save instead.
It would great if I could just take advantage of the new async/await features of coffeescript 2.0 and do this instead:
coffee> wikijs = require('wikijs')
coffee> batman = await wikijs().page('batman')
coffee> batman
{
links: [Function: links],
categories: [Function: categories],
coordinates: [Function: coordinates],
info: [Function: n],
backlinks: [Function: backlinks],
rawImages: [Function: f],
mainImage: [Function: mainImage]
}
coffee> await batman.mainImage()
'https://upload.wikimedia.org/wikipedia/en/7/74/Batman_Detective_Comics_Vol_2_1'Which adjust perfectly with the philosophy of a REPL which is providing you with an environment to quickly and easily test and prototype stuff out.
Metadata
Metadata
Assignees
Labels
No labels