fix(lib/modules/finders/get): undefined unsub function on immediately found lookup
This commit is contained in:
parent
ab41ec060f
commit
f1e94fe634
2 changed files with 19 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { noop } from '@revenge-mod/utils/callback'
|
||||
import { asap, noop } from '@revenge-mod/utils/callback'
|
||||
import {
|
||||
lookupModule,
|
||||
lookupModuleByImportedPath,
|
||||
|
|
@ -88,7 +88,11 @@ export function getModule(
|
|||
if (max === 1) {
|
||||
const [exports, id] = lookupModule(filter, options!)
|
||||
if (id !== undefined) {
|
||||
callback(exports, id)
|
||||
// Run callback at the end of the event loop
|
||||
// This ensures that the noop is returned first
|
||||
asap(() => {
|
||||
callback(exports, id)
|
||||
})
|
||||
return noop
|
||||
}
|
||||
} else
|
||||
|
|
|
|||
|
|
@ -12,4 +12,17 @@ export function debounce<F extends (...args: any[]) => any>(
|
|||
})
|
||||
}
|
||||
|
||||
const now = (cb: () => any) => {
|
||||
cb()
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that runs the callback as soon as possible.
|
||||
* @param cb The callback to run.
|
||||
*/
|
||||
export const asap = (cb: (...args: any[]) => any) => {
|
||||
// @ts-expect-error
|
||||
;(HermesInternal.enqueueJob ?? setImmediate ?? now)(cb)
|
||||
}
|
||||
|
||||
export const noop = () => {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue