diff --git a/docs/api/js.rst b/docs/api/js.rst index 64598b7a..9b851859 100644 --- a/docs/api/js.rst +++ b/docs/api/js.rst @@ -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