New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose Container constructor #108
Conversation
So we can use bluebird's `Promise.promisifyAll` method
Not sure about this one. If we going to expose things, it is going to be everything or nothing. Now, I'm not sure if we should expose them for this use case. |
@apocas I updates the request, now it exposes all constructors (let me know if I missed any). Basically what docker.listImages({}, function (err, images) {
docker.createContainer({}, function (err, container) {
container.start(function (err) {
container.exec({}, function(err, exec) {
exec.start({}, function (err, stream) {
// ...
});
});
});
});
}); can becomes: docker.listImagesAsync()
.then(function (images) {
return docker.createContainerAsync();
})
.tap(function (container) {
return container.startAsync();
})
.then(function (container) {
return container.execAsync();
})
.then(function (exec) {
return exec.startAsync()
})
.then(function (stream) {
// ...
})
.catch(function () {
// catch all errors here
}); which is flat when nesting a lot of callbacks. Without exposing constructors, I am currently doing: Promise.promisifyAll(Docker.prototype);
var _getContainer = Docker.prototype.getContainer;
Docker.prototype.getContainer = function () {
var container = _getContainer.apply(this, arguments);
if (!container.startAsync) {
Promise.promisifyAll(Object.getPrototypeOf(container));
}
return container;
} |
Have you checked https://www.npmjs.com/package/dockerode-promise from @lightsofapollo ? |
|
Yeah exactly. |
I see, thanks. |
@daiweilu I believe the result of this is https://github.com/daiweilu/Dockership , correct? |
@amitaibu Not exactly, https://github.com/daiweilu/Dockership/blob/master/lib/promisified/docker-promisified.js is the file that convert Dockerode into promise style. |
👍 |
Awesome! There were a few people asking for this 👍 |
Please include promise interface into this repository. Promise-wrapping packages quickly become out of date... |
+1 sheerun. Why are callback still a thing... |
I'd like to second this. All of the "wrapped" versions haven't been updated in over a year. Trying to do anything complex with this quickly leads to callback hell. |
I will expose all the constructors to make all of you promise lovers happier :) I'm not saying that what we have right now leads to a callback hell, I continue to say that really depends on the writer's habits, schools, patterns, taste, ... Just want Dockerode to be a really good base structure to everyone :) |
Here we go: Happy to announce that I implemented a promises based interface :) https://github.com/apocas/dockerode#promises-yet-to-be-published |
Looks fine to me :)
…On Thu, Mar 2, 2017 at 4:46 AM, Pedro Dias ***@***.***> wrote:
Here we go:
8585228
<8585228>
Happy to announce that I implemented a promises based interface :)
Please comment and contribute, I really want feedback before even thinking
on publishing it.
https://github.com/apocas/dockerode#promises-yet-to-be-published
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#108 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAR2DbJQteEXFOW7Ue_Sedi_-q1YxUaiks5rhjuhgaJpZM4DB8-P>
.
|
Feedback needed: #339 |
So we can use bluebird's
Promise.promisifyAll
[1*] method like so:1 - https://github.com/petkaantonov/bluebird/blob/master/API.md#promisepromisifyallobject-target--object-options---object