Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return null when labels.len() <= 2 #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SyrinxStream extends Readable {
* @param {(error?: Error | null) => void} callback
*/
async _construct(callback) {
/** @type {[import("./native").PreparedSynthesizer, null] | [null, Error]} */
/** @type {[import("./native").PreparedSynthesizer | null, null] | [null, Error]} */
const [synthesizer, error] = await this._syrinx
.prepare(this._inputText, this._option)
.then(
Expand Down
2 changes: 1 addition & 1 deletion lib/native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export interface SyrinxConfig {
export class Syrinx {
static fromConfig(config: SyrinxConfig): Syrinx
static fromConfigAsync(config: SyrinxConfig): Promise<Syrinx>
prepare(inputText: string, option: SynthesisOption): Promise<PreparedSynthesizer>
prepare(inputText: string, option: SynthesisOption): Promise<PreparedSynthesizer | null>
}
export class PreparedSynthesizer {
synthesize(push: (...args: [err: null, frame: Buffer] | [err: Error, frame: null]) => void): Promise<void>
Expand Down
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Syrinx {
AsyncTask::new(FromConfigTask { config })
}

#[napi(ts_return_type = "Promise<PreparedSynthesizer>")]
#[napi(ts_return_type = "Promise<PreparedSynthesizer | null>")]
pub fn prepare(&self, input_text: String, option: SynthesisOption) -> AsyncTask<PrepareTask> {
let worker = self.0.clone();
AsyncTask::new(PrepareTask {
Expand Down Expand Up @@ -121,8 +121,8 @@ pub struct PrepareTask {
}

impl Task for PrepareTask {
type Output = PreparedSynthesizer;
type JsValue = PreparedSynthesizer;
type Output = Option<PreparedSynthesizer>;
type JsValue = Option<PreparedSynthesizer>;

fn compute(&mut self) -> napi::Result<Self::Output> {
self
Expand All @@ -136,6 +136,10 @@ impl Task for PrepareTask {
.extract_fullcontext(&self.input_text)
.map_err(|err| Error::new(Status::InvalidArg, err))?;

if labels.len() <= 2 {
return Ok(None);
}

let generator = self
.worker
.jbonsai
Expand All @@ -144,10 +148,10 @@ impl Task for PrepareTask {
let encoder: Box<dyn Encoder> =
Encoder::new(&self.worker.jbonsai.condition, &self.worker.encoder_config)?;

Ok(PreparedSynthesizer {
Ok(Some(PreparedSynthesizer {
generator: Some(Box::new(generator)),
encoder: Some(encoder),
})
}))
}

fn resolve(&mut self, _: Env, output: Self::Output) -> napi::Result<Self::JsValue> {
Expand Down