Skip to content

feat: prevent executing original function multiple times#677

Open
yofukashino wants to merge 10 commits intoreplugged-org:mainfrom
yofukashino:instead-injector
Open

feat: prevent executing original function multiple times#677
yofukashino wants to merge 10 commits intoreplugged-org:mainfrom
yofukashino:instead-injector

Conversation

@yofukashino
Copy link
Contributor

@yofukashino yofukashino commented Apr 3, 2025

Changes the instead patch logic to accept a function as return value from callback.
So that it can race condition functions like send message get executed only once after 2 seconds of sleep;

All Async patches are ran at the same time asynronously so it can cause issues but this is the best way if not introducing seperate async injector functions

Code Example:


  import { Injector, common, webpack, util } from "replugged";
 
  const injector = new Injector();
 
  export async function start() {
    injector.instead(common.messages, "sendMessage", async (_, origFunc) => {
      await Promise.resolve();
      return origFunc;
    });
    
     injector.instead(common.messages, "sendMessage", async (_, origFunc) => {
      await util.sleep(2000);
      return origFunc;
    });
  }
 
  export function stop() {
    injector.uninjectAll();
  }

@netlify
Copy link

netlify bot commented Apr 3, 2025

Deploy Preview for replugged-docs failed.

Name Link
🔨 Latest commit f131e73
🔍 Latest deploy log https://app.netlify.com/projects/replugged-docs/deploys/68a47c37fd63a80008337f7d

@fedeericodl fedeericodl added enhancement New feature or request semver: patch Requires a patch semver version bump labels Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request semver: patch Requires a patch semver version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants