context.done()
の中身が気になったので、ちょっとソースを出力してみた。
exports.handler = function(event, context) { console.log(context.done.toString()); };
2014-12-01T14:37:21.597Z 8813aa33-7967-11e4-9b88-b730c83d5e8a function (err, message) { if(doneStatus) { return; } doneStatus = true; var error = null; if(!(typeof err == "undefined" || (typeof err == "object" && !err))) { error = util.format(err); console.log(error); } /* * use a timeout to perform the operation once the user gives up control of the event thread * This is how HTTP handler works right now */ setTimeout(function() { postDone(error, message); }, 0); }
ふむ。
Developer Guideによると
The method takes two arguments.The first argument to done() should be null to indicate a successful outcome of the function. Any value other than null will be interpreted as an error result. The string representation of non-null values is automatically logged to the Amazon CloudWatch Logs stream. The second argument to done() is an optional message string; if present, it is displayed in the console for test invocations below the log output. The message argument can be used in both success and error cases.
とのこと。
if present, it is displayed in the console for
test invocations below the log output.
のconsole for
test invocations
がどうもCloudWatch Logsに出力されないような…
ちなみにpostDone()
のソースを表示しようとしたら、参照できなかった…。done()
がクロージャでどっかのコンテキストでpostDone()
を参照してるのかなー。JavaScriptってコンテキストまで引っ張ってこれたっけ?
どうでもいいけど、関数終了/戻り値のハンドリングを改善してほしい…