1
0
mirror of synced 2026-04-12 19:38:38 +08:00
Files
SnowFlake-IdGenerator/D/source/yitter/idgen/YitIdHelper.d
BitWorld a82d9cb063 !6 D语言移植
* Porting to D
* The pthread needed.
2021-04-08 21:04:43 +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();
}
}