Skip to content

Instantly share code, notes, and snippets.

diff --git a/src/coroutine.cc b/src/coroutine.cc
index f2a0d3d..3c9a8ad 100644
--- a/src/coroutine.cc
+++ b/src/coroutine.cc
@@ -20,8 +20,6 @@
using namespace std;
const size_t v8_tls_keys = 3;
-static pthread_key_t floor_thread_key = 0;
-static pthread_key_t ceil_thread_key = 0;
@laverdet
laverdet / patch.diff
Created December 12, 2014 03:27
node-fibers issue #158
diff --git a/src/coroutine.cc b/src/coroutine.cc
index f2a0d3d..64bf201 100644
--- a/src/coroutine.cc
+++ b/src/coroutine.cc
@@ -20,9 +20,10 @@
using namespace std;
const size_t v8_tls_keys = 3;
-static pthread_key_t floor_thread_key = 0;
-static pthread_key_t ceil_thread_key = 0;
@laverdet
laverdet / repl
Created April 30, 2015 06:18
fibers repl
#!/usr/bin/env node
"use strict";
var fs = require('fs');
var Future = require('fibers/future');
// Start the repl
var vm = require('vm');
var domain = require('domain');
var repl = require('repl').start('node> ', null, fiberEval, true, true);
function fiberEval(code, context, file, cb) {
@laverdet
laverdet / body.js
Created July 20, 2015 05:42
Screeps Body class
// Descriptor of a creep body
function Body(body) {
this.body = body;
this._isCreep = typeof body[0] === 'object';
this._cost = undefined;
this._weight = undefined;
}
_.assign(Body.prototype, {
@laverdet
laverdet / sorted.js
Last active August 29, 2015 14:25
How to merge sorted arrays
function mergeSorted(a, b) {
var array = new Array(a.length + b.length);
var ii = a.length + b.length - 1;
var jj = a.length - 1, kk = b.length - 1;
while (jj >= 0 || kk >= 0) {
array[ii--] = (jj < 0 || a[jj] < b[kk]) ? b[kk--] : a[jj--];
}
return array;
}
@laverdet
laverdet / gist:791157
Created January 22, 2011 14:39
node-fibers adapter example
$ cat adapter.js
require('./node-fibers');
var print = require('util').print;
// This function runs an asynchronous function from within a fiber as if it
// were synchronous.
function asyncAsSync(fn /* ... */) {
var args = [].slice.call(arguments, 1);
var fiber = Fiber.current;
@laverdet
laverdet / earlyfibers.diff
Created February 4, 2011 19:49
Test patch to fix issue #6 in laverdet/node-fibers
diff --git a/src/coroutine.cc b/src/coroutine.cc
index e1d8908..265faf4 100644
--- a/src/coroutine.cc
+++ b/src/coroutine.cc
@@ -42,7 +42,10 @@ static pthread_key_create_t& dyn_pthread_key_create();
* the original implementation but that doesn't work because dlsym() tries to get a lock which ends
* up calling pthread_getspecific and pthread_setspecific. So have to implement our own versions of
* these functions assuming one thread only and then as soon as we can, put all that saved data into
- * real TLS.
+ * a better structure.
String.prototype.method = function() {}
function func(str) {}
var stringObject = new String("hello world");
var stringPrimitive = "hello world";
exports.compare = {
"stringObject.method()": function() {
stringObject.method();
},
function Future() {}
Future.mixin({
didComplete: function(value) {
if (value === undefined) {
throw new TypeError('May not return undefined from future');
}
this._value = value;
var fibers = this._fibers;
if (fibers) {
@laverdet
laverdet / future.js
Created March 29, 2011 14:16
Simple future library which makes use of node-fibers for blocking operations
"use strict";
require('fibers');
this.Future = Future;
this.FiberFuture = FiberFuture;
this.wait = wait;
/**
* Return a function which automatically creates a fiber for each invocation.
*/