2018 TypeScript Update(4)LDAPJS and RESTful and Async
LDAP Guide
http://ldapjs.org/guide.html
LDAP - Lightweight Directory Access Protocol
Understand a Simple RESTful TypeScript
https://github.com/vrudikov/typescript-rest-boilerplate
> git clone https://github.com/vrudikov/typescript-rest-boilerplate
Go to that project, install the dependency
> npm install
Generate the swagger document
> npm run swagger
Start the Project
> npm start
Visit the URL
http://localhost:3000/
Some Tests Fail, Not Latest
Check this project
https://github.com/w3tecch/express-typescript-boilerplate
This Project seems great.
Understand Async in TypeScript
http://www.webhek.com/post/javascript-async-await-2.html
async means this function is async, await can only be inside this function.
await means wait for promise return value
await will follow by promise
Example
Begin with a simple example
var sleep = function(time) {
Return new Promise(function(resolve, reject){
setTimeout(function() { resolve();}, time);
})
}
var start = async function() {
console.log(’start’);
await sleep(3000);
console.log(‘end’);
}
Start();
Get Return Value
var sleep = function(time){
return new Promise(function(resolve, reject) {
setTimeout(function(){ resolve(‘ok’); }, time);
})
}
var start = async function() {
let result = await sleep(3000);
console.log(result);
};
Get the Error
var sleep = function (time) {
return new Promise(function(resolve, reject) {
setTimeout(function() { reject(‘error’); }, time);
})
};
var start = async function(){
try{
console.log(‘start’);
await sleep(3000); //error
console.log(‘end’);
}catch(err){
console.log(err);
}
};
References:
http://ldapjs.org/
http://ldapjs.org/guide.html
https://github.com/vrudikov/typescript-rest-boilerplate
2018 TypeScript Update(4)LDAPJS and RESTful and Async
猜你喜欢
转载自sillycat.iteye.com/blog/2418507
今日推荐
周排行