Skip to content

Commit 447ac89

Browse files
authored
Merge pull request #975 from bogeychan/bogey/945
fix: await nested async plugins
2 parents 042a3e8 + d871042 commit 447ac89

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3597,6 +3597,15 @@ export default class Elysia<
35973597
}
35983598

35993599
return instance
3600+
} else if (plugin.promisedModules.size > 0) {
3601+
for (const promise of plugin.promisedModules.promises)
3602+
this.promisedModules.add(promise)
3603+
3604+
this.promisedModules
3605+
.then(() => this._use(plugin))
3606+
.then((x) => x.compile())
3607+
3608+
return this
36003609
}
36013610

36023611
const { name, seed } = plugin.config

test/plugins/plugin.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Elysia } from '../../src'
2+
3+
import { describe, expect, it } from 'bun:test'
4+
import { req } from '../utils'
5+
6+
describe('Plugin', () => {
7+
it('await async nested plugin', async () => {
8+
const yay = async () => {
9+
await Bun.sleep(1_000)
10+
11+
return new Elysia({ name: 'yay' }).get('/yay', 'yay')
12+
}
13+
14+
const wrapper = new Elysia({ name: 'wrapper' }).use(yay())
15+
16+
const app = new Elysia().use(wrapper)
17+
18+
await app.modules
19+
20+
const response = await app.handle(req('/yay'))
21+
22+
expect(response.status).toBe(200)
23+
})
24+
})

0 commit comments

Comments
 (0)