MCPcopy Create free account
hub / github.com/codrops/RainEffect / notify

Function notify

demo/js/main.js:2681–2723  ·  view source on GitHub ↗
(record, isReject)

Source from the content-addressed store, hash-verified

2679 return isObject(it) && typeof (then = it.then) == 'function' ? then : false;
2680};
2681var notify = function(record, isReject){
2682 if(record.n)return;
2683 record.n = true;
2684 var chain = record.c;
2685 asap(function(){
2686 var value = record.v
2687 , ok = record.s == 1
2688 , i = 0;
2689 var run = function(react){
2690 var cb = ok ? react.ok : react.fail
2691 , ret, then;
2692 try {
2693 if(cb){
2694 if(!ok)record.h = true;
2695 ret = cb === true ? value : cb(value);
2696 if(ret === react.P){
2697 react.rej(TypeError('Promise-chain cycle'));
2698 } else if(then = isThenable(ret)){
2699 then.call(ret, react.res, react.rej);
2700 } else react.res(ret);
2701 } else react.rej(value);
2702 } catch(err){
2703 react.rej(err);
2704 }
2705 };
2706 while(chain.length > i)run(chain[i++]); // variable length - can't use forEach
2707 chain.length = 0;
2708 record.n = false;
2709 if(isReject)setTimeout(function(){
2710 var promise = record.p
2711 , handler, console;
2712 if(isUnhandled(promise)){
2713 if(isNode){
2714 process.emit('unhandledRejection', value, promise);
2715 } else if(handler = global.onunhandledrejection){
2716 handler({promise: promise, reason: value});
2717 } else if((console = global.console) && console.error){
2718 console.error('Unhandled promise rejection', value);
2719 }
2720 } record.a = undefined;
2721 }, 1);
2722 });
2723};
2724var isUnhandled = function(promise){
2725 var record = promise[RECORD]
2726 , chain = record.a || record.c

Callers 3

main.jsFile · 0.70
$rejectFunction · 0.70
$resolveFunction · 0.70

Calls 2

runFunction · 0.70
isUnhandledFunction · 0.70

Tested by

no test coverage detected