var screencastId = 'abc'
var a = youtube.get(screencastId);
a.then(function(screencast) {
// Great, the screencast information is now available.
console.log(screencast);
});
// How can I access the `screencast` variable below?
connection.beginTransactionAsync().then(function() {
return connection.queryAsync('INSERT IGNORE INTO Channels SET ?', screencast.channel);
}).then(function() {
return connection.queryAsync('INSERT INTO Screencasts SET ?', screencast);
}).then(function() {
var values = tags.map(function(tag) { return [tag]; });
return connection.queryAsync('INSERT IGNORE INTO Tags VALUES ?', [values])
}).then(function() {
var values = tags.map(function(tag) { return [screencast.screencastId, tag]; });
return connection.queryAsync('INSERT INTO ScreencastTags VALUES ?', [values])
}).then(function() {
return connection.commit();
}).error(function(e) {
connection.rollback();
winston.error(e);
});
This code breaks down into two main steps:
- Retrieve data about a particular
screencast
from YouTube via theyoutube
module. - Save details regarding that
screencast
in the database.
Both of these processes are asynchronous by nature.
My inquiry is, how do I access the screencast
parameter during the second step?
I came across this detailed response, but as someone with limited experience in JavaScript, I'm unsure how to implement it in this scenario.