@@ -109,10 +109,11 @@ async function seedContent(seed_data) {
109109 // time/order later, to ensure that all of the paths get seeded before all of the
110110 // courses, and all of the courses get seeded before all of the lessons while still
111111 // enabling the lessons to have access to the correct course ids and courses the path ids
112- const course_funcs = [ ] ;
113112 const lesson_funcs = [ ] ;
113+ const course_funcs = [ ] ;
114114 const path_funcs = [ ] ;
115115 // set up each path seed to be triggered later
116+ // this forEach loop fills the path_funcs array with callbacks
116117 seed_data . forEach ( path => {
117118 path_funcs . push ( async ( ) => {
118119 const { uuid : path_id } = await seedPath ( path ) ;
@@ -130,11 +131,15 @@ async function seedContent(seed_data) {
130131 } ) ;
131132 // TODO: error handling/graceful failure
132133 // map actually triggers the functions to start resolving
133- await Promise . all ( path_funcs . map ( func => func ( ) ) ) ;
134+ // now the path_funcs array is full of callbacks, the course_funcs and lesson_funcs arrays are empty
135+ await Promise . all ( path_funcs . map ( pathFunc => pathFunc ( ) ) ) ;
134136 console . log ( 'Finished seeding all paths' ) ;
135- await Promise . all ( course_funcs . map ( func => func ( ) ) ) ;
137+ // now path_funcs are all executed, so course_funcs now full of callbacks, lesson_funcs still empty
138+ await Promise . all ( course_funcs . map ( courseFunc => courseFunc ( ) ) ) ;
136139 console . log ( 'Finished seeding all courses' ) ;
137- await Promise . all ( lesson_funcs . map ( func => func ( ) ) ) ;
140+ // now path)funcs and course_funcs all executed, lesson_funcs now full of callbacks
141+ await Promise . all ( lesson_funcs . map ( lessonFunc => lessonFunc ( ) ) ) ;
142+ // now all functions have been executed
138143 console . log ( 'Finished seeding all lessons' ) ;
139144 console . log ( 'Seeding completed.' ) ;
140145}
0 commit comments