node-osmosis
node-osmosis copied to clipboard
Use real "thenable" promises
In the list of features, there is "Clean promise-like interface".
Can you show a simple example how to use this. Are there resolve()
and then()
functions?
I'm also struggling with the promise like interface. You can find a few examples right here: https://github.com/rchipka/node-osmosis/wiki#then
The main problem is to integrate it in other promise chains because of the then
function interface.
@alexander-heimbuch Thanks for pointing to this wiki https://github.com/rchipka/node-osmosis/wiki#then. Although i use osmosis extensively, and refer to this http://rchipka.github.io/node-osmosis/Command.html#then__anchor documentation thinking this is the only doc available on osmosis. However, I never knew there is more info in the wiki page.
A big thank you.
You are welcome. I'm working around osmosis with Bluebird
wrapping the osmosis call in a promise. Would be much more elegant if the then
function from osmosis would be a real promise so I could simply pass it through the promise chain.
import Bluebird from 'bluebird'
import osmosis from 'osmosis'
export default () =>
new Bluebird((resolve, reject) => {
osmosis.get(url)
.set({
foo: '.bar',
bar: '#baz'
})
.data((listing) => resolve({
foo: listing.foo.trim(),
bar: listing.bar.trim().replace(/\[.+?\]\s*/g, '')
}))
})
@alexander-heimbuch this is what i do as well!
I am satisfied with using bluebird as the solution and can't complain. osmosis simple and powerful API and being free is too good to complain about lack of a thenable promise.
I would like to avoid using real promises throughout because it would mean extending each Promise instance (or Promise.prototype) with Osmosis commands.
My thought is that .then()
could support passing in a promise. Additionally, if the user gives .done
a promise, then Osmosis could return that promise instead of the Osmosis instance, which would also allow the use of await
.