scala - Link promise to another -
i'm reading scala.concurrent.impl.promise , confused concept "link defaultpromise another". understand 'prevent memory leak' part, don't know how write example current state of defaultpromise defaultpromise.
when defaultpromise first created, state nil , list grows keep appending flatmap it. under circumstances branch
case dp: defaultpromise[_] => dp.asinstanceof[defaultpromise[s]].linkrootof(p) in future.flatmap called?
test("default promise linking") { //f1.getstate === nil val f1 = future {thread.sleep(200000); 2} //f1.getstate === list(callbackrunner1) f1.flatmap(x => future {thread.sleep(200000); 4}) //f1.getstate === list(callbackrunner2, callbackrunner1) f1.flatmap(y => future {thread.sleep(200000); 3}) thread.sleep(30000000) }
take example:
val f1 = future {thread.sleep(200000); 2} val f2 = f1.flatmap(x => { val f3 = future {thread.sleep(200000); 4} f3 }) f1 , f3 of course not share same state - 1 resolves 2 other 4. when f1 completes, handler (f(v)) create f3 , match the case confused about. then, f2 (p in flatmap) linked f3 share same state.
Comments
Post a Comment