-
-
Notifications
You must be signed in to change notification settings - Fork 239
chore: reduce production dependencies #1045
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
c0f3047
e880e5f
9e5d2c7
f4aebec
3d7fd28
1b3bb3d
cb8ca24
ac207b0
a86f22d
6fed21d
c2cc706
e8d6a4b
bfeb6ca
3a35a63
31a9bc1
6e4e287
b486014
e366386
b36916c
7313585
f0ed980
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,32 @@ | ||
| import fastfall from 'fastfall' | ||
| import Packet from 'aedes-packet' | ||
| import { through, validateTopic, $SYS_PREFIX } from '../utils.js' | ||
| import write from '../write.js' | ||
|
|
||
| const subscribeTopicActions = fastfall([ | ||
| function runFall (fns) { | ||
| // run functions in fastfall style, only need the single argument function | ||
| return function (arg, cb) { | ||
| let i = 0 | ||
| const ctx = this | ||
| function next (err, nextarg) { | ||
| if (err || i === fns.length) { | ||
| if (typeof cb === 'function') { | ||
| cb.call(ctx, err, nextarg) | ||
| } | ||
| return | ||
| } | ||
| const fn = fns[i++] | ||
| fn.call(ctx, nextarg, next) | ||
| } | ||
| next(null, arg) | ||
| } | ||
| } | ||
|
robertsLando marked this conversation as resolved.
Outdated
|
||
|
|
||
| const subscribeTopicActions = runFall([ | ||
| authorize, | ||
| storeSubscriptions, | ||
| addSubs | ||
| ]) | ||
| const restoreTopicActions = fastfall([ | ||
| const restoreTopicActions = runFall([ | ||
| authorize, | ||
| addSubs | ||
| ]) | ||
|
|
@@ -78,14 +96,24 @@ function _dedupe (subs) { | |
| return ret | ||
| } | ||
|
|
||
| function handleSubscribe (client, packet, restore, done) { | ||
| async function handleSubscribe (client, packet, restore, done) { | ||
| packet.subscriptions = packet.subscriptions.length === 1 ? packet.subscriptions : _dedupe(packet.subscriptions) | ||
| client.broker._parallel( | ||
| new SubscribeState(client, packet, restore, done), // what will be this in the functions | ||
| doSubscribe, // function to call | ||
| packet.subscriptions, // first argument of the function | ||
| restore ? done : completeSubscribe // the function to be called when the parallel ends | ||
| ) | ||
| const state = new SubscribeState(client, packet, restore, done) | ||
| try { | ||
| await Promise.all(packet.subscriptions.map(sub => new Promise((resolve, reject) => { | ||
| doSubscribe.call(state, sub, (err, result) => { | ||
| if (err) reject(err) | ||
| else resolve(result) | ||
| }) | ||
| }))) | ||
| if (restore) { | ||
| done() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that if this throws, it would call done twice
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why, can you please explain? I tried the following: const pOk = new Promise(resolve => {
console.log('pOK will resolve')
resolve()
})
const pFail = new Promise((resolve,reject) => {
console.log('pFail will reject')
reject('pFail rejected')
})
try {
await Promise.all([pOk,pFail])
console.log('all Promises resolved ok')
} catch (err){
console.log('At least one promise failed, first error:', err)
}This gives me: Btw: I reworked doSubscribe to make this part more easy to read.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seriousme — the concern is not the
try {
await Promise.all(...)
completeSubscribe.call(state) // queues done via write(), then throws
} catch (err) {
done(err) // catch calls done
}
// next tick: setImmediate fires → done called AGAINMinimal repro: const state = { finish: function(err){ console.log('DONE', err?.message ?? 'OK') } }
function write (cb) { setImmediate(cb) }
function completeSubscribe () {
write(state.finish)
throw new Error('listener threw')
}
async function doSub () { return Promise.resolve() }
async function handleSubscribe () {
try {
await Promise.all([doSub()])
completeSubscribe.call(state)
} catch (err) {
state.finish(err)
}
}
handleSubscribe()
// → DONE listener threw
// → DONE OK ← second invocationFix direction: move the post-
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @seriousme |
||
| } else { | ||
| completeSubscribe.call(state) | ||
| } | ||
| } catch (err) { | ||
| done(err) | ||
| } | ||
|
seriousme marked this conversation as resolved.
robertsLando marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function doSubscribe (sub, done) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,13 +40,19 @@ function handleUnsubscribe (client, packet, done) { | |
| } | ||
| } | ||
|
|
||
| function actualUnsubscribe (client, packet, done) { | ||
| const broker = client.broker | ||
| broker._parallel( | ||
| new UnsubscribeState(client, packet, done), | ||
| doUnsubscribe, | ||
| packet.unsubscriptions, | ||
| completeUnsubscribe) | ||
| async function actualUnsubscribe (client, packet, done) { | ||
| const state = new UnsubscribeState(client, packet, done) | ||
| try { | ||
| await Promise.all(packet.unsubscriptions.map(sub => new Promise((resolve, reject) => { | ||
| doUnsubscribe.call(state, sub, (err, result) => { | ||
| if (err) reject(err) | ||
| else resolve(result) | ||
| }) | ||
| }))) | ||
| completeUnsubscribe.call(state) | ||
| } catch (err) { | ||
| completeUnsubscribe.call(state, err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new But the symmetric case now opens up the same shape as the subscribe thread: on the success path, Same fix shape: wrap |
||
| } | ||
|
seriousme marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function doUnsubscribe (sub, done) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.