#!/usr/bin/env bash
set +e;
No official CS education but I learned about readers-writer locks after implementing a mutex library. I happened to come across a real-world use case that I would need this for.
Say we have many people signing up to take a class, their payment (through Stripe, or whatever) might be in flight. And imagine the teacher cancels the class, which would trigger a refund event.
Without proper locking, the refund might fail to execute for those students whose payments are in flight at the time of the class cancelation.
First run this code:
const exec = () => {
setTimeout(() => {
throw 'nothing can catch this, except domains';
},10);
};
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Stringifiable = object | string | boolean | number | null; | |
export const stdMarker = 'gfy'; | |
export const getJSONCanonical = function (v: Stringifiable, marker?: string) { | |
marker = marker || stdMarker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(1); | |
new Promise(function(resolve,reject){ | |
console.log(2); | |
resolve(); | |
}).then(function(val){ | |
console.log(3); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Rx = require('rxjs'); | |
console.log(1); | |
new Promise(function(resolve,reject){ | |
console.log(2); | |
resolve(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import opq | |
const Queue = require('opq'); | |
// below we create a new client to the queue, | |
// and create the queue on the filesystem if it does | |
// not exist. the port is used by Live-Mutex; | |
// fp is our queue filepath | |
const q = new Queue({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// asynchronous constructor example, | |
// like always do not explictly return anything from the constructor | |
function Queue(){ | |
this.ready = false; | |
let callable = true; | |
let ee = new EE(); // new event emitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** | |
** Example of Interprocess communication in Node.js through a UNIX domain socket | |
** | |
** Usage: | |
** server> MODE=server node ipc.example.js | |
** client> MODE=client node ipc.example.js | |
** | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func main() { | |
// We need to cast handleRoot to a http.HandlerFunc since wrapHandlerWithLogging |
NewerOlder