「Node.js」util.callbackifyを使うサンプル

構文
const util = require('util’);

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const util = require('util');
async function fn() {
return 'this is a message';
}
const callbackFunction = util.callbackify(fn);
callbackFunction((err, ret) => {
if (err) throw err;
console.log(ret);
});
const util = require('util'); async function fn() { return 'this is a message'; } const callbackFunction = util.callbackify(fn); callbackFunction((err, ret) => { if (err) throw err; console.log(ret); });
const util = require('util');

async function fn() {
  return 'this is a message';
}
const callbackFunction = util.callbackify(fn);

callbackFunction((err, ret) => {
  if (err) throw err;
  console.log(ret);
});

結果
this is a message

Node.js

Posted by arkgame