apparat is a simple but powerful way to organize async code for nodejs
npm install apparat
read domain from file
write resolved IPV4 addresses to
write resolved IPV6 addresses to
addresses6.txt in parallel.
domain.txt when both files have been written successfully.
fs = require 'fs'dns = require 'dns'apparat = require 'apparat'apparatdebug consolelogonError throw errfsreadFile 'domain.txt'send 'contents'receive 'contents'domain = contentstoStringtrim# paralleldnsresolve4 domainsend 'addresses4'dnsresolve6 domainsend 'addresses6'receive 'addresses4'fswriteFile 'addresses4.txt'addressesjoin'\n'send 'addresses4 written'receive 'addresses6'fswriteFile 'addresses6.txt'addressesjoin'\n'send 'addresses6 written'receive 'addresses4 written''addresses6 written'->fsunlink 'domain.txt'send 'deleted'receive 'deleted'->consolelog 'OK'