Skip to content

Instantly share code, notes, and snippets.

View SamanShafigh's full-sized avatar

Saman Shafigh SamanShafigh

View GitHub Profile
@SamanShafigh
SamanShafigh / async-await.js
Created July 19, 2018 03:06
ES6 async/await
// We can also use async/await which is a Syntactic Sugar For Promises
var addC = function (a, b) {
return new Promise((resolve, reject) => {
setTimeout (() => {
resolve(a + b);
}, 0);
});
};
import {MongoClient} from 'mongodb';
import UserController from './controller/user-controller';
import UserService from './service/user-service'
import MongoDriver from './service/db-service';
import Config from './service/config-service';
export const config = {
constructor: () => new Config(process.env),
tags: ['boot']
}
import Container from './container';
export default class Kernel {
constructor(builder) {
this.container = new Container(builder);
}
/**
* Boot the kernel, load all services
*/
export default class Container {
constructor(builder) {
this.services = new Map();
if (builder !== undefined) {
Object.keys(builder).forEach(name => this.register(name, builder[name]));
}
}
/**
* Register a service
import Kernel from './kernel';
import * as ServiceBuilder from './service';
(async () => {
const kernel = new Kernel(ServiceBuilder);
await kernel.boot();
await kernel.container.get('db').save('product', {}, {id: 1, name: 'ssssscar'});
})();