Comments (8)
process.nextTick = (f, ...args) => {
uWS.nextTick(() => f(...args));
}
the speard works also with arrays thats why this gets (arg1,arg2,arg3)
i am glad that i could help i saw your rant about NPM and i want to tell you your right it was the right way to do it i am a big fan of it !!!!! π
from uwebsockets.js.
but you got that already in your code apply would look like
process.nextTick = (f, ...args) => {
console.log(this instanceof global) //=> true!
uWS.nextTick(() => f.apply(this, args));
} // this is in this case most time the global object of nodejs or in case of browser window
function withName() {
console.log(this instanceof global) //=> true!
uWS.nextTick(() => f.apply(this, args));
}.bind(this)
function withName() {
console.log(this instanceof global) //=> false!
console.log(this instanceof withName) //=> true!
uWS.nextTick(() => f.apply(this, args));
}
in a JS file directly used bind(this) is eqal to not using bind(this) as arrow function don't have own scope
importent side note () => arrow functions are using the outer scope as this so inside a named function the function is the scope if used directly the global object is the scope
from uwebsockets.js.
cant write all examples but if you point me to a file with some pseudo code i get it working for you with comments
from uwebsockets.js.
This is what I had:
process.nextTick = (f, ...args) => uWS.nextTick(f.apply(...args));
Which is obviously wrong, but worked good enough for me not to find an issue until now.
I thought this would solve it:
process.nextTick = (f, ...args) => uWS.nextTick(() => {f.apply(...args);});
But it doesn't work..?
If this works, that's like Golang and simple:
process.nextTick = (f, ...args) => {
uWS.nextTick(() => f(...args));
}
from uwebsockets.js.
While the syntax of this function is almost identical to that of call(), the fundamental difference is that call() accepts an argument list, while apply() accepts a single array of arguments.
Apply signature: (context, args)
So when you call f.apply(context, ars) it's same as:
f.call(context, ...args)
and
f.bind(context)(...args)
But if you don't need context setting (set internal this
of function), you can just use splat syntax:
f(...args)
Hope this helps
from uwebsockets.js.
Yeah it helped, it works now at least. Thanks
from uwebsockets.js.
You're welcome. Thank you for UWS
from uwebsockets.js.
@alexhultman the code is wrong apply works directly with arrays
don't use spread 3 dot operator when using apply it expects a array as secund argument
f.apply(context, args)
f.call(context, ...args)
from uwebsockets.js.
Related Issues (20)
- Allow for dynamically-generated certificates, keys, etc. HOT 1
- Parameter routes routing issue HOT 2
- There is a way to get the number of client connections from Node.js? HOT 2
- Consider queueing headers on `HttpResponse.setHeader` call HOT 3
- Underscores in HTTP header key silently drops request HOT 4
- H3App: segmentation fault HOT 1
- Setting idleTimeout to a big value crashes the process HOT 3
- How to reduce real-time audio and video stream forwarding delayοΌ HOT 4
- Windows binaries don't build
- WriteStatus function
- req.getQuery() is returning undefiend insteated of empty string HOT 2
- HttpRequest that survives past async functions HOT 19
- Auto compression for HTTP and use zstd HOT 2
- NODE_MODULE_VERSION 93 in:uNetworking/uWebSockets.js HOT 5
- uWebSockets.js can't be installed using npm install uNetworking/uWebSockets.js#v20.43.0 HOT 1
- U can setup base middleware system smth like this: HOT 1
- listen_unix no working
- HttpResponse onData method HOT 3
- security question: Can i disable `Uwebsockets` header? HOT 1
- node 22 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uwebsockets.js.