1
0
mirror of synced 2026-10-31 12:16:39 +08:00
Files
SnowFlake-IdGenerator/zzz-OtherLanguages/D/source/yitter/idgen/YitIdHelper.d
2021-04-09 21:15:41 +08:00

44 lines
1.1 KiB
D
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 版权属于:yitter(yitter@126.com)
* 开源地址:https://gitee.com/yitter/idgenerator
*/
module yitter.idgen.YitIdHelper;
import yitter.idgen.DefaultIdGenerator;
import yitter.contract.IIdGenerator;
import yitter.contract.IdGeneratorException;
import yitter.contract.IdGeneratorOptions;
import std.concurrency : initOnce;
/**
* 这是一个调用的例子,默认情况下,单机集成者可以直接使用 nextId()。
*/
class YitIdHelper {
private __gshared IIdGenerator idGenInstance = null;
static IIdGenerator getIdGenInstance() {
return initOnce!idGenInstance(new DefaultIdGenerator(new IdGeneratorOptions(1)));
}
/**
* 设置参数,建议程序初始化时执行一次
*/
static void setIdGenerator(IdGeneratorOptions options) {
idGenInstance = new DefaultIdGenerator(options);
}
/**
* 生成新的Id
* 调用本方法前,请确保调用了 SetIdGenerator 方法做初始化。
*
* @return
*/
static long nextId() {
return getIdGenInstance().newLong();
}
}