Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crowd-client

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crowd-client - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

94

index.js

@@ -5,16 +5,17 @@ module.exports = CrowdClient

this.workers = []
// handle opts like credential or id
return this
this.interface = null;
// handle opts like credential or id
return this
}
CrowdClient.prototype.use = function(interface) {
this.interface = interface
this.interface = interface
return this
return this
}
CrowdClient.prototype.pipe = function(worker) {
this.workers.push(worker)
this.workers.push(worker)
return this
return this
}

@@ -24,28 +25,69 @@

// For now just return first worker in the list
return workers[id || 0]
return this.workers[id || 0]
}
CrowdClient.prototype.get = function() {
var _this = this
CrowdClient.prototype.parseTask = function(raw) {
this.interface
.get()
.success(function(task) {
_this.getWorker(task, _this.send)
})
.failure(function(error) {
console.log(error)
})
task = JSON.parse(raw)
try {
task.data = JSON.parse(task.data)
} catch(err) {
// it is fine, task data will be the same
}
task.code = this.eval(task.code)
return task
}
CrowdClient.prototype.send = function(result) {
this.interface
.send(data)
.success(function(task) {
_this.getWorker(task, _this.send)
})
.failure(function(error) {
console.log(error)
})
CrowdClient.prototype.get = function(cb) {
var client = this
this.interface.get(function(err, raw) {
if (err) throw new Error(err)
if (cb) cb(null, client.parseTask(raw))
})
return this
}
CrowdClient.prototype.send = function(result, cb) {
var client = this
this.interface.send(result, function(err, raw) {
if (err) throw new Error(err)
if (cb) cb(null, client.parseTask(raw))
})
return this
}
CrowdClient.prototype.eval = function (code) {
var body = code.substring(code.indexOf("{") + 1, code.lastIndexOf("}"));
return new Function("data", "next", body)
}
CrowdClient.prototype.start = function (opts, cb) {
this.get(this.runTask(opts, cb))
return this
}
CrowdClient.prototype.runTask = function(opts, cb) {
var client = this
if (typeof opts == "function") cb = opts
return function(err, task) {
if (opts === true) cb = client.runTask(opts, cb)
if (err) throw new Error(err)
var worker = client.getWorker()
worker.start(task, function(err, result) {
client.send(result, cb)
})
}
}
{
"name": "crowd-client",
"version": "0.0.1",
"version": "0.0.2",
"description": "Generic client for crowd",

@@ -23,3 +23,5 @@ "main": "index.js",

},
"homepage": "https://github.com/nicola/crowd-client"
"homepage": "https://github.com/nicola/crowd-client",
"dependencies": {
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc