Skip to content

Commit

Permalink
fix: functions that return promises should be async
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper committed Jul 19, 2019
1 parent 1e9a0af commit 1504b66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable require-atomic-updates */
import logger from 'debug';
import ms from 'ms';
import { RedisClient } from 'redis';

const debug = logger('koa-simple-ratelimit');

function find(db: RedisClient, p: string): Promise<string> {
async function find(db: RedisClient, p: string): Promise<string> {
return new Promise((resolve, reject) => {
db.get(p, (err, reply) => {
if (err) {
Expand All @@ -16,7 +17,7 @@ function find(db: RedisClient, p: string): Promise<string> {
});
}

function pttl(db: RedisClient, p: string): Promise<number> {
async function pttl(db: RedisClient, p: string): Promise<number> {
return new Promise((resolve, reject) => {
db.pttl(p, (err, reply) => {
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('ratelimit middleware', () => {
.end(done);
});

it('should not limit if `id` returns `false`', () => {
it('should not limit if `id` returns `false`', async () => {
const app = new Koa();

app.use(
Expand Down Expand Up @@ -290,7 +290,7 @@ describe('ratelimit middleware', () => {
}),
);

app.use((ctx, next) => {
app.use(async (ctx, next) => {
ctx.body = ctx.request.header.foo;
return next();
});
Expand Down

0 comments on commit 1504b66

Please sign in to comment.