ios - How do I wait in a flattenMap block for a signal to complete before the next event is consumed? -
here pseudo code :
[[[@[ctx1,ctx2]rac_sequence]signalwithscheduler:racscheduler.immediatescheduler] flattenmap:^racstream *(id ctx) { // first flatten map return [racsignal createsignal:^(id <racsubscriber> subscriber) { [executerequestasynch ondone:^{ [subscriber sendnext:ctx]; [subscriber sendcompleted]; } ] }] flattenmap:^racstream *(id ctx) { // second flattenmap }]; }
now here want happen upon subscribe:
1) ctx1 should fed first flattenmap block 2) server request "executerequestasynch" should called 3) on completion of serverrequest second flattenmap should called ctx1 4) ctx2 should fed first flattenmap block 5) server request "executerequestasynch" should called 6) on completion of serverrequest second flattenmap should called ctx1
but instead scenario happens:
1) ctx1 gets fed first flattenmap block 2) server request "executerequestasynch" called 3) ctx2 gets fed first flattenmap block 4) server request "executerequestasynch" called 5) on completion of serverrequest second flattenmap called ctx1 6) on completion of serverrequest second flattenmap called ctx2
how can make first scenario happen?
answer seems work! thanks: output is:
step 1 step 1 child step 1 child child step 2 step 2 child step 2 child child done
i still wondering defer achieve in underneath senario
-(racsignal*) executerequestasynch:(nsstring*) ctx { return [racsignal createsignal:^racdisposable * (id<racsubscriber> subscriber) { nslog(@" %@ child",ctx); [subscriber sendcompleted]; return nil; }]; } -(racsignal*) executerequestasynch2:(nsstring*) ctx { return [racsignal createsignal:^racdisposable * (id<racsubscriber> subscriber) { nslog(@" %@ child child",ctx); [subscriber sendcompleted]; return nil; }]; } - (void)viewdidload { [super viewdidload]; racsignal *contexts = [[@[ @"step 1", @"step 2" ] rac_sequence] signalwithscheduler:racscheduler.immediatescheduler]; racsignal *ne = [[contexts map:^(id ctx) { nslog(@"%@",ctx); return [[self executerequestasynch:ctx] concat: [self executerequestasynch2:ctx ]];}]concat] ; [ne subscribecompleted:^{ nslog(@"done all"); }]; }
i'm not 100% sure understand you're trying accomplish. interpretation like:
racsignal *contexts = [@[ ctx1, ctx2 ] things.rac_sequence signalwithscheduler:racscheduler.immediatescheduler]; [[contexts map:^(id ctx) { return [executerequestasynch concat:[racsignal defer:^{ // returns signal involving ctx? }]]; }] concat];
this maps each of context executerequestasynch
, , concats them done serially.
is right or did misunderstand you?
Comments
Post a Comment