docs: Improve Mopidy.js promise usage examples

Thanks to @briancavalier for the review!
This commit is contained in:
Stein Magnus Jodal 2014-06-16 23:46:17 +02:00
parent 3cf1973652
commit 6864cc97ea

View File

@ -329,17 +329,19 @@ Example to get started with
var queueAndPlay = function (playlistNum, trackNum) {
playlistNum = playlistNum || 0;
trackNum = trackNum || 0;
mopidy.playlists.getPlaylists().done(function (playlists) {
mopidy.playlists.getPlaylists().then(function (playlists) {
var playlist = playlists[playlistNum];
console.log("Loading playlist:", playlist.name);
mopidy.tracklist.add(playlist.tracks).done(function (tlTracks) {
mopidy.playback.play(tlTracks[trackNum]).done(function () {
mopidy.playback.getCurrentTrack().done(function (track) {
return mopidy.tracklist.add(playlist.tracks).then(function (tlTracks) {
return mopidy.playback.play(tlTracks[trackNum]).then(function () {
return mopidy.playback.getCurrentTrack().then(function (track) {
console.log("Now playing:", trackDesc(track));
});
});
});
});
})
.catch(console.error.bind(console)) // Handle errors here
.done(); // ...or they'll be thrown here
};
var mopidy = new Mopidy(); // Connect to server
@ -372,7 +374,7 @@ Example to get started with
// anywhere in the chain.
var args = arguments;
return mopidy.playback.getCurrentTrack()
.done(function (track) {
.then(function (track) {
console.log("Now playing:", trackDesc(track));
return args;
});
@ -395,7 +397,11 @@ Example to get started with
// => TlTrack
.then(mopidy.playback.play)
// => null
.done(printNowPlaying, console.error.bind(console));
.then(printNowPlaying)
// => null
.catch(console.error.bind(console)) // Handle errors here
// => null
.done(); // ...or they'll be thrown here
};
var mopidy = new Mopidy(); // Connect to server