public override Task <IList <MarketDataVM> > SubMarketDataAsync(IEnumerable <ContractKeyVM> instrIDList, int timeout = 10000) { var tcs = new TimeoutTaskCompletionSource <IList <MarketDataVM> >(timeout); var serialId = NextSerialId; #region callback MessageWrapper.RegisterAction <PBPricingDataList, ExceptionMessage> (MSG_ID_SUB_MD, (resp) => { if (resp.Header?.SerialId == serialId) { tcs.TrySetResult(SubMDSuccessAction(resp)); } }, (bizErr) => { if (bizErr.SerialId == serialId) { tcs.TrySetException(new MessageException(bizErr.MessageId, ErrorType.BIZ_ERROR, bizErr.Errorcode, bizErr.Description.ToStringUtf8())); } } ); #endregion SendMessage(serialId, MSG_ID_SUB_MD, instrIDList); return(tcs.Task); }
public Task <IList <ContractKeyVM> > SubTradingDeskDataAsync(IEnumerable <ContractKeyVM> instrIDList, int timeout = 10000) { var msgId = (uint)BusinessMessageID.MSG_ID_SUB_TRADINGDESK_PRICING; var tcs = new TimeoutTaskCompletionSource <IList <ContractKeyVM> >(timeout); var serialId = NextSerialId; #region callback MessageWrapper.RegisterAction <PBInstrumentList, ExceptionMessage> (msgId, (resp) => { if (resp.Header?.SerialId == serialId) { tcs.TrySetResult(SubTDSuccessAction(resp)); } }, (bizErr) => { if (bizErr.SerialId == serialId) { tcs.TrySetException(new MessageException(bizErr.MessageId, ErrorType.BIZ_ERROR, bizErr.Errorcode, bizErr.Description.ToStringUtf8())); } } ); #endregion SendMessage(serialId, msgId, instrIDList); return(tcs.Task); }
public async Task <int> ReadAsync(byte[] buffer, int offset, int count) { trigger = new TimeoutTaskCompletionSource(this.ReadTimeout); if (this.BytesToRead > 0) { return(await ReadAsyncInternal(buffer, offset, count)); } else { await trigger.TimeoutTask; if (trigger.TimeoutTask.Result) { return(await ReadAsyncInternal(buffer, offset, count)); } else { return(0); } } }