-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Transformer による実装を変換処理のチェーンへと変更 #374
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
無責任reviewです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なんかだいじょうぶそう (小並感)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
無責任わからせapprove
🎉 This PR is included in version 1.22.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Close #372.
Type of Change:
コードの修正
Cause of the Problem (問題の原因)
tuple.ts
では, 反変関手の unzip 処理として(bs: [B1, B2]) => Promise<void>
を[(b1: B1) => Promise<void>, (b2: B2) => Promise<void>]
へと変換するsplit
関数が存在していました. しかしこの実装では, 関数の引数を片方づつ受け取って溜め込み, 両方が揃ったら送り出すという実装になっていました. このために実行タイミングによっては正しく動作しない可能性があり, 再現性がないバグの原因となっていました.Dealing with Problems (問題への対処)
そもそも反変関手の性質上 unzip 処理は不可能であるため, 根本的に複雑過ぎた変換処理を見直すことにしました. メッセージハンドラと同じ形の
Promise
を返すだけの関数を用いて, その関数が拒否された場合はメッセージの変換処理もといメッセージへの応答を中断する方針で実装することにしました.Details of implementation (実施内容)
middleware.ts
を追加し, メッセージM
をメッセージN
へ変換する処理Middleware<M, N>
を追加しました。これは単純なPromise
チェーンによって結合され、これまでのボットのフィルタやコマンド向けの変換処理も同様に実装できます.これによって, 「作成されたメッセージへの変換処理」を「更新されたメッセージへの変換処理」へと加工する
liftTuple
関数も用意に実装できました. そのためこちらはmiddleware.ts
内へと移動しています.