feat: 초기 프로젝트 설정 및 룰.md 파일 추가
This commit is contained in:
21
api.hyungi.net/node_modules/culvert/LICENSE
generated
vendored
Normal file
21
api.hyungi.net/node_modules/culvert/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Tim Caswell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
102
api.hyungi.net/node_modules/culvert/README.md
generated
vendored
Normal file
102
api.hyungi.net/node_modules/culvert/README.md
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
Culvert
|
||||
=======
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
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.
|
||||
|
||||
```js
|
||||
// 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.
|
||||
|
||||
```js
|
||||
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.
|
||||
|
||||
## makeChannel(bufferSize, monitor)
|
||||
|
||||
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.
|
||||
|
||||
## channel.put(item) -> more
|
||||
|
||||
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.
|
||||
|
||||
## channel.drain(callback)
|
||||
|
||||
Drain is a reusable continuable. Use this when you want to wait for the buffer to be below the bufferSize mark.
|
||||
|
||||
## channel.take(callback)
|
||||
|
||||
Take is for reading. The callback will have the next item. It may call sync or it may be later.
|
||||
67
api.hyungi.net/node_modules/culvert/channel.js
generated
vendored
Normal file
67
api.hyungi.net/node_modules/culvert/channel.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = makeChannel;
|
||||
|
||||
function makeChannel(bufferSize, monitor) {
|
||||
bufferSize = bufferSize|0;
|
||||
var dataQueue = [];
|
||||
var readQueue = [];
|
||||
var drainList = [];
|
||||
|
||||
if (typeof monitor === "string") {
|
||||
monitor = log(monitor);
|
||||
}
|
||||
|
||||
return {
|
||||
drain: drain,
|
||||
put: put,
|
||||
take: take,
|
||||
};
|
||||
|
||||
function drain(callback) {
|
||||
if (typeof callback !== "function") {
|
||||
throw new TypeError("callback must be function");
|
||||
}
|
||||
if (dataQueue.length <= bufferSize) return callback();
|
||||
drainList.push(callback);
|
||||
}
|
||||
|
||||
// Returns true when it's safe to continue without draining
|
||||
function put(item) {
|
||||
if (monitor) monitor("put", item);
|
||||
if (readQueue.length) {
|
||||
if (monitor) monitor("take", item);
|
||||
readQueue.shift()(null, item);
|
||||
}
|
||||
else {
|
||||
dataQueue.push(item);
|
||||
}
|
||||
return dataQueue.length <= bufferSize;
|
||||
}
|
||||
|
||||
function take(callback) {
|
||||
if (typeof callback !== "function") {
|
||||
throw new TypeError("callback must be function");
|
||||
}
|
||||
if (dataQueue.length) {
|
||||
var item = dataQueue.shift();
|
||||
if (monitor) monitor("take", item);
|
||||
callback(null, item);
|
||||
if (dataQueue.length <= bufferSize && drainList.length) {
|
||||
var list = drainList;
|
||||
drainList = [];
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
list[i]();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
readQueue.push(callback);
|
||||
}
|
||||
}
|
||||
|
||||
function log(name) {
|
||||
return function (type, value) {
|
||||
console.info(name, type, value);
|
||||
};
|
||||
}
|
||||
15
api.hyungi.net/node_modules/culvert/consume.js
generated
vendored
Normal file
15
api.hyungi.net/node_modules/culvert/consume.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = consume;
|
||||
|
||||
function consume(channel, emit) {
|
||||
return function (callback) {
|
||||
channel.take(onItem);
|
||||
function onItem(err, item) {
|
||||
if (item === undefined) return callback(err);
|
||||
try { emit(item); }
|
||||
catch (err) { return callback(err); }
|
||||
channel.take(onItem);
|
||||
}
|
||||
};
|
||||
}
|
||||
25
api.hyungi.net/node_modules/culvert/package.json
generated
vendored
Normal file
25
api.hyungi.net/node_modules/culvert/package.json
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "culvert",
|
||||
"version": "0.1.2",
|
||||
"description": "Channel for easy streaming of work between complex logics.",
|
||||
"main": "channel.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/creationix/culvert.git"
|
||||
},
|
||||
"keywords": [
|
||||
"channel",
|
||||
"stream",
|
||||
"csp",
|
||||
"js-git"
|
||||
],
|
||||
"author": "Tim Caswell <tim@creationix.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/creationix/culvert/issues"
|
||||
},
|
||||
"homepage": "https://github.com/creationix/culvert"
|
||||
}
|
||||
Reference in New Issue
Block a user