![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Channel for easy streaming of work between complex logics.
This is used in place of streams for CSP style flow. I use it in js-git for network and file streams.
Usually, you'll want to split sides to create a duplex channel.
var makeChannel = require('culvert');
var serverChannel = makeChannel();
var clientChannel = makeChannel();
function connect(host, port) {
// This represents the server-side of the duplex pipe
var socket = {
put: serverChannel.put,
drain: serverChannel.drain,
take: cientChannel.drain
};
// When we want to send data to the consumer...
socket.put(someData);
// When we want to read from the consumer...
socket.take(function (err, item) {});
// Return the client's end of the pipe
return {
put: clientChannel.put,
drain: clientChannel.drain,
take: serverChannel.take
};
}
If you want/need to preserve back-pressure and honor the buffer limit,
make sure to wait for drain when put
returns false.
// Start a read
socket.take(onData);
function onData(err, item) {
if (err) throw err;
if (item === undefined) {
// End stream when nothing comes out
console.log("done");
}
else if (socket.put(item)) {
// If put returned true, keep reading
socket.take(onData);
}
else {
// Otherwise pause and wait for drain
socket.drain(onDrain);
}
}
function onDrain(err) {
if (err) throw err;
// Resume reading
socket.take(onData);
}
If you're using continuables and generators, it's much nicer syntax.
var item;
while (item = yield socket.take, item !== undefined) {
if (!socket.put(item)) yield socket.drain;
}
console.log("done");
Also the continuable version won't blow the stack if lots of events come in on the same tick.
Create a new channel.
The optional bufferSize is how many items can be in the queue and still be considered not full.
The optional monitor function will get called with (type, item)
where type
is either "put" or "take" and item
is the value being put or taken.
This is a sync function. You can add as many items to the channel as you want and it will queue them up.
This returns true
when the queue is smaller than bufferSize, it returns false if you should wait for drain.
Drain is a reusable continuable. Use this when you want to wait for the buffer to be below the bufferSize mark.
Take is for reading. The callback will have the next item. It may call sync or it may be later.
FAQs
Channel for easy streaming of work between complex logics.
The npm package culvert receives a total of 1,139,434 weekly downloads. As such, culvert popularity was classified as popular.
We found that culvert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.