Dobrym sposobem, aby poradzić sobie z FUNKCJE asynchroniczny w node.js
jest za pomocą decofun debug tool.
Jego główną cechą jest przetwarzanie kodu i nazw anonimowych funkcji zgodnie z ich kontekstem.
Można deanonymise dowolny anonimowy funkcja uruchamiając go z deco filename.js
Prostym przykładem byłoby jak wspomniano w documentation
function gravy() {
return function returnedᅠfromᅠgravyᅠㅣlineᅠ2() {
return {
prop: function asᅠpropertyᅠpropᅠㅣlineᅠ4() {
setTimeout(function passedᅠintoᅠsetTimeoutᅠㅣlineᅠ5() {
console.trace('Getting a trace...');
}, 10)
}
}
}
}
Trace: Getting a trace...
at passedᅠintoᅠsetTimeoutᅠㅣlineᅠ5 [as _onTimeout] (/home/ubuntu/workspace/node_modules/decofun/examples/loadable/index.js:6:22)
at Timer.listOnTimeout (timers.js:92:15)
Ponieważ pochodzi z wbudowanego cute-stack biblioteki, która normalizuje ścieżka do bieżącego katalogu
Stosując polecenie deco examples/loadable --cute table
wyjście zostanie pokazane jako
Najlepiej lubię w nim to, że przekształca funkcje w oparciu o ich połączeń do pierwotnego jak widać w Przykład z tego
function one (a, cb) {
}
one('blah', function() {
})
function two() {
return function() { }
}
function three() {
return {
shoe: function() {}
}
}
function four() {
return function() {
return function() {
}
}
}
function five() {
return function() {
return function() {
return function() {
foo('blue', function() {
})
}
}
}
}
var six = function() {
}
var seven = function (err, cb) {
return function() {
cb(function() {
})
}
}
var o = {};
o.eight = function (cb) { }
o.eight(function() { })
o.eight.nine = function() {}
o.eight.nine(function() { })
var o2;
o2 = function() { }
;(function() {}())
!function() { }()
function toodeep() {
return function() {
return function() {
return function() {
return function() {
return function() {
return function() {
return function() {
return function() {
return function() {
return function() {
}
}
}
}
}
}
}
}
}
}
}
do tego
function one (a, cb) {
}
one('blah', function passedᅠintoᅠoneᅠㅣlineᅠ6() {
})
function two() {
return function returnedᅠfromᅠtwoᅠㅣlineᅠ11() { }
}
function three() {
return {
shoe: function asᅠpropertyᅠshoeᅠㅣlineᅠ17() {}
}
}
function four() {
return function returnedᅠfromᅠfourᅠㅣlineᅠ22() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠfourᅠᐳᅠㅣlineᅠ23() {
}
}
}
function five() {
return function returnedᅠfromᅠfiveᅠㅣlineᅠ30() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠfiveᅠᐳᅠㅣlineᅠ31() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠfiveᅠᐳᅠᐳᅠㅣlineᅠ32() {
foo('blue', function passedᅠintoᅠfooᅠㅣlineᅠ33() {
})
}
}
}
}
var six = function asᅠvarᅠsixᅠㅣlineᅠ42() {
}
var seven = function asᅠvarᅠsevenᅠㅣlineᅠ47 (err, cb) {
return function returnedᅠfromᅠᐸᅠasᅠvarᅠsevenᅠᐳᅠㅣlineᅠ49() {
cb(function passedᅠintoᅠcbᅠㅣlineᅠ50() {
})
}
}
var o = {};
o.eight = function asᅠpropertyᅠeightᅠㅣlineᅠ58 (cb) { }
o.eight(function passedᅠintoᅠoːeightᅠㅣlineᅠ61() { })
o.eight.nine = function asᅠpropertyᅠnineᅠㅣlineᅠ63() {}
o.eight.nine(function passedᅠintoᅠeightːnineᅠㅣlineᅠ64() { })
var o2;
o2 = function asᅠvarᅠo2ᅠㅣlineᅠ68() { }
;(function IIFEᅠㅣlineᅠ71() {}())
!function IIFEᅠㅣlineᅠ73() { }()
function toodeep() {
return function returnedᅠfromᅠtoodeepᅠㅣlineᅠ78() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠtoodeepᅠᐳᅠㅣlineᅠ79() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠtoodeepᅠᐳᅠᐳᅠㅣlineᅠ80() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠtoodeepᅠᐳᅠᐳᅠᐳᅠㅣlineᅠ82() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠtoodeepᅠᐳᅠᐳᅠᐳᅠᐳᅠㅣlineᅠ83() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠtoodeepᅠᐳᅠᐳᅠᐳᅠᐳᅠᐳᅠㅣlineᅠ84() {
return function returnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠᐸᅠreturnedᅠfromᅠtoodeepᅠᐳᅠᐳᅠᐳᅠᐳᅠᐳᅠᐳᅠㅣlineᅠ86() {
return function() {
return function() {
return function() {
}
}
}
}
}
}
}
}
}
}
}
Mam nadzieję, że to może trochę pomóc! Twoje zdrowie!
proszę dodać OS używasz. W niektórych systemach operacyjnych można używać narzędzi do śledzenia, takich jak dtrace (smartos), itp., Aby zobaczyć, co dzieje się w produkcji bez dotykania kodu. –