How to use the threads.Thread.terminate function in threads

To help you get started, we’ve selected a few threads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ChainSafe / lodestar / packages / lodestar / src / chain / factory / block / index.ts View on Github external
parentRoot: signingRoot(parentHeader, config.types.BeaconBlockHeader),
    // @ts-ignore
    signature: undefined,
    // @ts-ignore
    stateRoot: undefined,
    body: await assembleBody(config, opPool, eth1, merkleTree, currentState, randao),
  };

  const stat = await spawn(new Worker("../../../../../eth2.0-state-transition/src/stateTransition"))

  block.stateRoot = hashTreeRoot(
    await stat(config, currentState, block, false, false),
    config.types.BeaconState
  );

  await Thread.terminate(stat)
  return block;
}
github satoshipay / solar / src / lib / stellar-ticker.ts View on Github external
export async function fetchAllAssets(testnet: boolean): Promise {
  const storageKey = testnet ? "known-assets:testnet" : "known-assets:mainnet"

  const cachedAssetsString = localStorage.getItem(storageKey)
  const timestamp = localStorage.getItem("known-assets:timestamp")

  if (cachedAssetsString && timestamp && +timestamp > Date.now() - 24 * 60 * 60 * 1000) {
    // use cached assets if they are not older than 24h
    return JSON.parse(cachedAssetsString)
  } else {
    const fetcher = await spawn(new Worker("../workers/fetch-worker.ts"))
    const allAssets = await fetcher.fetchAllAssets(testnet)
    await Thread.terminate(fetcher)

    localStorage.setItem(storageKey, JSON.stringify(allAssets))
    localStorage.setItem("known-assets:timestamp", Date.now().toString())

    return allAssets
  }
}
github satoshipay / solar / src / lib / stellar-expert.ts View on Github external
export async function fetchWellknownAccounts(testnet: boolean): Promise {
  const cacheKey = testnet ? "known-accounts:testnet" : "known-accounts:mainnet"

  const cachedAccountsString = localStorage.getItem(cacheKey)
  const timestamp = localStorage.getItem("known-accounts:timestamp")

  if (cachedAccountsString && timestamp && +timestamp > Date.now() - 24 * 60 * 60 * 1000) {
    // use cached accounts if they are not older than 24h
    return JSON.parse(cachedAccountsString)
  } else {
    const fetcher = await spawn(new Worker("../workers/fetch-worker.ts"))
    const knownAccounts = await fetcher.fetchWellknownAccounts(testnet)
    await Thread.terminate(fetcher)

    localStorage.setItem(cacheKey, JSON.stringify(knownAccounts))
    localStorage.setItem("known-accounts:timestamp", Date.now().toString())
    return knownAccounts
  }
}