Last active
July 2, 2017 04:21
-
-
Save afrontend/fafa9f7f30028a6d0e735114f6eab487 to your computer and use it in GitHub Desktop.
Async 모듈 사용 후 도서 검색 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
appendBookId(booklist, body); | |
var tasks = []; | |
_.each(booklist, function(book, key) { | |
var o = _.clone(opt); | |
o.bookId = book.bookId; | |
tasks.push(function (callback) { | |
searchDetail(o, function (err, exist) { | |
if (err) { | |
exist = false; | |
} | |
callback(null, exist); | |
}); | |
}) | |
}); | |
async.parallel(tasks, function (err, results) { | |
if (err) { | |
getBook({msg: 'Error, Can\'t access detail information'}); | |
return; | |
} | |
if (getBook) { | |
booklist = _.map(booklist, function (item, key) { | |
item.exist = results[key]; | |
return item; | |
}); | |
getBook(null, { | |
startPage: opt.startPage, | |
totalBookCount: totalBookCount, | |
booklist: booklist | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment