We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To: Tapir
面试公司: 未知
面试环节: 一面
问题: 如何将 node 标准的回调 API 在 fibjs 内转为"同步"调用形式
The text was updated successfully, but these errors were encountered:
fibjs 可以使用 util.sync 将 callback 或者 async 函数转变为 sync 函数,并且直接调用。
callback 例子:
var util = require('util'); function cb_test(a, b, cb) { setTimeout(() => { cb(null, a + b); }, 100); } var fn_sync = util.sync(cb_test); console.log(fn_sync(100, 200));
async 例子:
var util = require('util'); async function async_test(a, b) { return a + b; } var fn_sync = util.sync(async_test); console.log(fn_sync(100, 200));
async/await 例子:
var util = require('util'); function async_test(a, b) { return new Promise(function(resolve, reject) { resolve(a + b); }); } var fn_sync = util.sync(async_test, true); console.log(fn_sync(100, 200));
Sorry, something went wrong.
tapir-dream
No branches or pull requests
To:
Tapir
面试公司:
未知
面试环节:
一面
问题:
如何将 node 标准的回调 API 在 fibjs 内转为"同步"调用形式
The text was updated successfully, but these errors were encountered: