Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 同步呼叫(等待ad.authenticate)_Javascript_Node.js_Asynchronous_Async Await_Node Modules - Fatal编程技术网

Javascript 同步呼叫(等待ad.authenticate)

Javascript 同步呼叫(等待ad.authenticate),javascript,node.js,asynchronous,async-await,node-modules,Javascript,Node.js,Asynchronous,Async Await,Node Modules,如何进行异步调用?我尝试使用以下代码: abc = await ad.authenticate(username, password, function(err, auth) { if(err){ console.log('ERROR: '+JSON.stringify(err)); fail_found = err.name; return; } if(auth

如何进行异步调用?我尝试使用以下代码:

abc = await ad.authenticate(username, password, function(err, auth) {
          if(err){
            console.log('ERROR: '+JSON.stringify(err));
            fail_found = err.name;
            return;
          }

          if(auth){
            console.log('Authenticated!');
          }else{
            console.log('Authenticated Faliled');
            fail_found = 'No Authenticated ';
          }          
        });
      }
      console.log("Fails?: ",fail_found);
NPM: Github:

谢谢

您可以尝试使用:

或者在文档的第一部分显示一个允诺包装:

const AD = require('activedirectory2').promiseWrapper;
const config = { url: 'ldap://dc.domain.com',
           baseDN: 'dc=domain,dc=com',
           username: 'username@domain.com',
           password: 'password' }
const ad = new AD(config);
您可以尝试以下方法:

或者在文档的第一部分显示一个允诺包装:

const AD = require('activedirectory2').promiseWrapper;
const config = { url: 'ldap://dc.domain.com',
           baseDN: 'dc=domain,dc=com',
           username: 'username@domain.com',
           password: 'password' }
const ad = new AD(config);

您发布的第一个链接,
承诺包装器通过备用require语句可用于所有方法
您发布的第一个链接,
承诺包装器通过备用require语句可用于所有方法
,但它不是同步的。```log('----start');然后((successMessage)=>{console.log(successMessage);}).catch(err=>{console.log(err)});console.log('----end')```例如,我将首先检查用户是否存在,他们检查是否可以进行身份验证,但如果用户不存在,我不需要检查身份验证。Wenn同时异步这两个检查。现在可以了,我忘记了异步函数asd(){wait…,wait…}。谢谢,格雷西亚斯:)但它不是同步的log('----start');然后((successMessage)=>{console.log(successMessage);}).catch(err=>{console.log(err)});console.log('----end')```例如,我将首先检查用户是否存在,他们检查是否可以进行身份验证,但如果用户不存在,我不需要检查身份验证。Wenn同时异步这两个检查。现在可以了,我忘记了异步函数asd(){wait…,wait…}。谢谢,格雷西亚斯:)