This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Dataloader = require("dataloader") | |
| const fakeAsync = (content, t) => new Promise(res => setTimeout(_ => { | |
| console.log("content:", content) | |
| content = content.map(c => c + 1) | |
| res(content) | |
| }, t)) | |
| async function start() { | |
| const testLoader = new Dataloader(async (keys) => { | |
| console.log("batched by dataloader: ", keys) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class tPromise { | |
| constructor(fn){ | |
| this.status = "pedding" | |
| this._queue = [] | |
| this._catch = ()=>{ console.error("unhandle tPromise error") } | |
| fn.call(this, this.resolve.bind(this), this.reject.bind(this)) | |
| } | |
| resolve(data){ | |
| this.status = "resolved"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Koa = require('koa'); | |
| const app = new Koa(); | |
| app.use(async (ctx, next) => { | |
| try { | |
| await next(); | |
| }catch(error){ | |
| console.error(error); | |
| ctx.body = "ServerError"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express') | |
| require('express-async-errors') | |
| var app = express() | |
| var pE = require("./promisifyError") | |
| var rt = express.Router(); | |
| app.get('/', async function (req, res, next) { | |
| await pE(); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import path = require('path'); | |
| import cdk = require('@aws-cdk/cdk'); | |
| import lambda = require('@aws-cdk/aws-lambda'); | |
| import event = require('@aws-cdk/aws-events'); | |
| export class AwsCdkStack extends cdk.Stack { | |
| constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { | |
| super(scope, id, props); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| import cdk = require('@aws-cdk/cdk'); | |
| import { AwsCdkStack } from '../lib/aws-cdk-stack'; | |
| const app = new cdk.App(); | |
| new AwsCdkStack(app, 'AwsCdkStack', { | |
| env: { | |
| region: 'us-west-1' | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var net = require('net'); | |
| var opts = { | |
| host: 'localhost', | |
| port: 3000 | |
| } | |
| var socket = net.connect(opts, function () { | |
| socket.end('GET / HTTP/1.0\r\n' + | |
| 'Host: localhost\r\n' + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| const keepAliveAgent = new http.Agent({ | |
| keepAlive: true, | |
| // 多久發一次 tcp keep-alive 檢查 | |
| keepAliveMsecs: 4000 | |
| }); | |
| const options = { | |
| hostname: 'localhost', | |
| port: 3000, | |
| path: '/', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| events { | |
| worker_connections 1024; | |
| } | |
| http { | |
| keepalive_timeout 65; | |
| server { | |
| listen 80; | |
| location / { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| events { | |
| worker_connections 1024; | |
| } | |
| http { | |
| keepalive_timeout 65; | |
| server { | |
| listen 80; | |
| location / { |