Skip to content

Delay execution of dispatched events #359

@piranna

Description

@piranna

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch mock-socket@9.1.3 for the project I'm working on.

Events from server to client needs to have some delay to mimic network delay.

Here is the diff that solved my problem:

diff --git a/node_modules/mock-socket/dist/mock-socket.js b/node_modules/mock-socket/dist/mock-socket.js
index 2478234..414d406 100644
--- a/node_modules/mock-socket/dist/mock-socket.js
+++ b/node_modules/mock-socket/dist/mock-socket.js
@@ -793,13 +793,16 @@ EventTarget.prototype.dispatchEvent = function dispatchEvent (event) {
     return false;
   }
 
-  listeners.forEach(function (listener) {
-    if (customArguments.length > 0) {
-      listener.apply(this$1, customArguments);
-    } else {
-      listener.call(this$1, event);
-    }
-  });
+  delay(function()
+  {
+    listeners.forEach(function (listener) {
+      if (customArguments.length > 0) {
+        listener.apply(this$1, customArguments);
+      } else {
+        listener.call(this$1, event);
+      }
+    });
+  })
 
   return true;
 };

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions