Skip to content

Commit

Permalink
Fix async stream issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkidu93 committed Oct 16, 2024
1 parent ec30ff9 commit 31a31c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/Echo/src/EchoTranslationEngine/TranslationEngineServiceV1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace EchoTranslationEngine;
using Nito.AsyncEx.Synchronous;

namespace EchoTranslationEngine;

public class TranslationEngineServiceV1(BackgroundTaskQueue taskQueue) : TranslationEngineApi.TranslationEngineApiBase
{
Expand Down Expand Up @@ -83,11 +85,11 @@ await client.BuildStartedAsync(
ParallelCorpusPreprocessor.PreprocessCorpora(
request.Corpora.Select(Map).ToList(),
row => { },
async (row, corpus) =>
(row, corpus) =>
{
if (row.SourceSegment.Length > 0 && row.TargetSegment.Length == 0)
{
await call.RequestStream.WriteAsync(
call.RequestStream.WriteAsync(
new InsertPretranslationsRequest
{
EngineId = request.EngineId,
Expand All @@ -97,7 +99,8 @@ await call.RequestStream.WriteAsync(
Translation = row.SourceSegment
},
cancellationToken
);
)
.WaitAndUnwrapException();
}
},
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ CancellationToken cancellationToken
pretranslateWriter.WriteStartArray();
ParallelCorpusPreprocessor.PreprocessCorpora(
corpora,
async row =>
row =>
{
await sourceTrainWriter.WriteAsync($"{row.SourceSegment}\n");
await targetTrainWriter.WriteAsync($"{row.TargetSegment}\n");
sourceTrainWriter.Write($"{row.SourceSegment}\n");
targetTrainWriter.Write($"{row.TargetSegment}\n");
if (row.SourceSegment.Length > 0 && row.TargetSegment.Length > 0)
trainCount++;
},
Expand Down

0 comments on commit 31a31c3

Please sign in to comment.