Skip to content

Instantly share code, notes, and snippets.

🏐
Focusing

Operations Research Engineering Software+ ORESoftware

🏐
Focusing
Block or report user

Report or block ORESoftware

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ORESoftware
ORESoftware / promises.ts
Last active Mar 11, 2019
promise api technique
View promises.ts
export class Worker {
getLock(v: string, cb: Function){
this.getLockInternal(v,cb);
}
getLockp(v:string){
return new Promise((resolve,reject) => {
this.getLockInternal(v, (err,result) => {
View null.9.ts
const passAStringOrNull = (v: StringOrNull) => {
let input: String;
if(v == null){
input = "default string";
}
else {
input = v;
}
return goDoDatabaseStuff(input);
View null.8.ts
const passAStringOrNull = (v: StringOrNull) => {
if(v == null){
v = "default string";
}
return goDoDatabaseStuff((String)v);
}
View null.7.ts
const goDoDatabaseStuff = (v: String) => {
return doWhatever();
}
View null.6.ts
const passAStringOrNull = (v: StringOrNull) => {
return goDoDatabaseStuff(v);
}
View null.5.ts
const getAStringOrNull = (v: Object) : StringOrNull => {
return v === bar ? v.toString() : null;
};
View null.4.ts
var x = getAStringOrNullWithoutSafety();
if(x != null) {
log.info(x.charAt(0));
}
View null.3.ts
log.info(withoutSafety().charAt(0)); // might throw an NPE
View null.2.ts
const withoutSafety = (v: Object) : String => {
return v === bar ? v.toString() : null;
};
View null.1.ts
type StringOrNull = String | null;
You can’t perform that action at this time.