-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Filip Maj
committed
Feb 10, 2022
1 parent
9782020
commit f6fc378
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: Deferring App initialization | ||
lang: en | ||
slug: deferring-initialization | ||
order: 8 | ||
--- | ||
|
||
<div class="section-content"> | ||
Bolt offers a way to defer full initialization via the `deferInitialization` option and to call the equivalent `App#init()` in your code, putting more control over asynchronous execution required for initialization into your hands as the developer. | ||
|
||
_Note: If you call `start()` before `init()`, Bolt will raise an exception._ | ||
</div> | ||
|
||
```javascript | ||
const { App } = require('@slack/bolt'); | ||
|
||
// deferInitialization is one of the options you can set in the constructor | ||
const app = new App({ | ||
token, | ||
signingSecret, | ||
deferInitialization: true, | ||
}); | ||
|
||
(async () => { | ||
try { | ||
// Must call init() before start() within an async function | ||
await app.init(); | ||
// Now safe to call start() | ||
await app.start(process.env.PORT || 3000); | ||
} catch (e) { | ||
console.log(e); | ||
process.exit(1); | ||
} | ||
})() | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: アプリの初期化の遅延 | ||
lang: ja | ||
slug: deferring-initialization | ||
order: 8 | ||
--- | ||
|
||
<div class="section-content"> | ||
Bolt は `deferInitialization` というオプションを使うことで、アプリの初期化処理の完了を遅延させることができます。このオプションを使う場合、あなたのコードの中で遅延された初期化処理部分に対応する `App#init()` メソッドを呼び出す必要がありますが、こうすることで初期化に必要となる非同期処理の実行をよりコントロールすることが可能となります。 | ||
|
||
_注意: `init()` メソッドを呼び出す前に `start()` メソッドを呼び出した場合、 Bolt は例外を発生させます。_ | ||
</div> | ||
|
||
```javascript | ||
const { App } = require('@slack/bolt'); | ||
|
||
// deferInitialization はコンストラクターで指定できるオプション | ||
const app = new App({ | ||
token, | ||
signingSecret, | ||
deferInitialization: true, | ||
}); | ||
|
||
(async () => { | ||
try { | ||
// 非同期関数の中で start() メソッドを呼び出す前に init() メソッドを呼び出すこと | ||
await app.init(); | ||
// init() メソッドを呼び出したので、`start()` メソッドを安全に呼び出すことができる | ||
await app.start(process.env.PORT || 3000); | ||
} catch (e) { | ||
console.log(e); | ||
process.exit(1); | ||
} | ||
})() | ||
``` |
This file contains 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
This file contains 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