fix(lib/modules/finders/get): undefined unsub function on immediately found lookup

This commit is contained in:
PalmDevs 2025-08-03 14:17:47 +07:00
parent ab41ec060f
commit f1e94fe634
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 19 additions and 2 deletions

View file

@ -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

View file

@ -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 = () => {}