MCPcopy Create free account
hub / github.com/chain/Core / nextPage

Function nextPage

sdk/node/src/shared.js:170–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

168 }
169
170 const nextPage = () => {
171 queryOwner.query(nextParams).then(page => {
172 let index = 0
173 let item
174
175 const next = () => {
176 if (index >= page.items.length) {
177 if (page.lastPage) {
178 done()
179 } else {
180 nextParams = page.next
181 nextPage()
182 }
183 return
184 }
185
186 item = page.items[index]
187 index++
188
189 // Pass the next item to the processor, as well as two loop
190 // operations:
191 //
192 // - next(): Continue to next item
193 // - done(err): Then terminate the loop by fulfilling the outer promise
194 //
195 // The process can also terminate the loop by returning a promise
196 // that will reject.
197
198 let res = processor(item, next, done)
199 if (res && typeof res.catch === 'function') {
200 res.catch(reject)
201 }
202 }
203
204 next()
205 }).catch(reject) // fail processor loop on query failure
206 }
207
208 nextPage()
209 })

Callers 4

nextFunction · 0.85
shared.jsFile · 0.85
nextMethod · 0.85
constructorMethod · 0.85

Calls 2

nextFunction · 0.85
queryMethod · 0.80

Tested by

no test coverage detected