Skip to content

Commit

Permalink
refactor: async not required
Browse files Browse the repository at this point in the history
  • Loading branch information
zhmushan committed Jan 10, 2019
1 parent 12eab08 commit c14fff2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions abc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ class AbcImpl implements Abc {
}
}

export type handlerFunc = (c: Context) => Promise<any>;
export type handlerFunc = (c: Context) => Promise<any> | any;
export type middlewareFunc = (h: handlerFunc) => handlerFunc;

export const NotFoundHandler: handlerFunc = async c => {
export const NotFoundHandler: handlerFunc = c => {
c.response.status = Status.NotFound;
c.response.body = new TextEncoder().encode(STATUS_TEXT.get(Status.NotFound));
};
export const InternalServerErrorHandler: handlerFunc = async c => {
export const InternalServerErrorHandler: handlerFunc = c => {
c.response.status = Status.InternalServerError;
c.response.body = new TextEncoder().encode(
STATUS_TEXT.get(Status.InternalServerError)
Expand Down
10 changes: 5 additions & 5 deletions abc_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const methods = [
t("abc handler", async () => {
const app = abc();
app
.any("/string", async c => data.string)
.any("/html", async c => data.html)
.any("/json", async c => data.json)
.any("/undefined_0", async c => undefined)
.any("/undefined_1", async c => {
.any("/string", c => data.string)
.any("/html", c => data.html)
.any("/json", c => data.json)
.any("/undefined_0", c => undefined)
.any("/undefined_1", c => {
c.string(data.undefined);
})
.start("0.0.0.0:4500");
Expand Down
4 changes: 2 additions & 2 deletions sample/01_cat_app/cat_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Context } from "https://deno.land/x/abc/mod.ts";
let catId = 1;
const cats = [] as Cat[];

export async function findAll() {
export function findAll() {
return cats;
}

export async function findOne(c: Context) {
export function findOne(c: Context) {
const { id } = c.params as { id: string };
return cats.find(cat => cat.id.toString() === id);
}
Expand Down

0 comments on commit c14fff2

Please sign in to comment.