Promise - GradedJestRisk/js-training GitHub Wiki
A promise is not - a function
const aPromise = {
then: (onFulfilled, onRejected)=>{ onFulfilled({ name: 'toto'})},
};
Idea: https://dorp.io/posts/railway-oriented-programming/
Specs
- as text: https://promisesaplus.com/#notes
- as test :https://github.com/promises-aplus/promises-tests/blob/master/lib/tests/2.1.2.js
const x = await v
v['then'] {return v.then((r)=>{ const x = r }
hashPassword: (password) => {
const foo = bcrypt.hash(password, NUMBER_OF_SALT_ROUNDS);
return foo.then((value)=>{return value;});
}
hashPassword.then((..));
Same as
hashPassword: async (password) => {
const foo = await bcrypt.hash(password, NUMBER_OF_SALT_ROUNDS);
},
Same as
hashPassword: (password) => {
return bcrypt.hash(password, NUMBER_OF_SALT_ROUNDS);
},
const f = () => { a() };
f.foo = () => { b()) };
Implemented as
f = {
_prototype : Function.prototype,
_body: { a() },
foo : { b() },
}
f() => a()
f.foo() => a()
An object with an operator ()